1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # This file is distributed under the same license as the PACKAGE package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
9 "Project-Id-Version: PACKAGE VERSION\n"
10 "POT-Creation-Date: 2013-09-28 04:06+0900\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <LL@li.org>\n"
16 "Content-Type: text/plain; charset=CHARSET\n"
17 "Content-Transfer-Encoding: 8bit\n"
20 #: build/C/man3/sem_close.3:26
26 #: build/C/man3/sem_close.3:26 build/C/man3/sem_destroy.3:26 build/C/man3/sem_getvalue.3:26 build/C/man3/sem_init.3:26 build/C/man3/sem_open.3:26 build/C/man7/sem_overview.7:26 build/C/man3/sem_post.3:26 build/C/man3/sem_unlink.3:26 build/C/man3/sem_wait.3:26
32 #: build/C/man3/sem_close.3:26 build/C/man3/sem_destroy.3:26 build/C/man3/sem_getvalue.3:26 build/C/man3/sem_init.3:26 build/C/man3/sem_open.3:26 build/C/man7/sem_overview.7:26 build/C/man3/sem_post.3:26 build/C/man3/sem_unlink.3:26 build/C/man3/sem_wait.3:26 build/C/man2/semctl.2:41 build/C/man2/semget.2:36 build/C/man2/semop.2:35
38 #: build/C/man3/sem_close.3:26 build/C/man3/sem_destroy.3:26 build/C/man3/sem_getvalue.3:26 build/C/man3/sem_init.3:26 build/C/man3/sem_open.3:26 build/C/man7/sem_overview.7:26 build/C/man3/sem_post.3:26 build/C/man3/sem_unlink.3:26 build/C/man3/sem_wait.3:26 build/C/man2/semctl.2:41 build/C/man2/semget.2:36 build/C/man2/semop.2:35
40 msgid "Linux Programmer's Manual"
44 #: build/C/man3/sem_close.3:27 build/C/man3/sem_destroy.3:27 build/C/man3/sem_getvalue.3:27 build/C/man3/sem_init.3:27 build/C/man3/sem_open.3:27 build/C/man7/sem_overview.7:27 build/C/man3/sem_post.3:27 build/C/man3/sem_unlink.3:27 build/C/man3/sem_wait.3:27 build/C/man2/semctl.2:42 build/C/man2/semget.2:37 build/C/man2/semop.2:36
50 #: build/C/man3/sem_close.3:29
51 msgid "sem_close - close a named semaphore"
55 #: build/C/man3/sem_close.3:29 build/C/man3/sem_destroy.3:29 build/C/man3/sem_getvalue.3:29 build/C/man3/sem_init.3:29 build/C/man3/sem_open.3:29 build/C/man3/sem_post.3:29 build/C/man3/sem_unlink.3:29 build/C/man3/sem_wait.3:29 build/C/man2/semctl.2:44 build/C/man2/semget.2:39 build/C/man2/semop.2:38
61 #: build/C/man3/sem_close.3:32 build/C/man3/sem_destroy.3:32 build/C/man3/sem_getvalue.3:32 build/C/man3/sem_init.3:32 build/C/man3/sem_post.3:32 build/C/man3/sem_unlink.3:32 build/C/man3/sem_wait.3:32
63 msgid "B<#include E<lt>semaphore.hE<gt>>\n"
67 #: build/C/man3/sem_close.3:34
69 msgid "B<int sem_close(sem_t *>I<sem>B<);>\n"
73 #: build/C/man3/sem_close.3:37 build/C/man3/sem_destroy.3:37 build/C/man3/sem_getvalue.3:37 build/C/man3/sem_init.3:37 build/C/man3/sem_open.3:41 build/C/man3/sem_post.3:37 build/C/man3/sem_unlink.3:37 build/C/man3/sem_wait.3:41
74 msgid "Link with I<-pthread>."
78 #: build/C/man3/sem_close.3:37 build/C/man3/sem_destroy.3:37 build/C/man3/sem_getvalue.3:37 build/C/man3/sem_init.3:37 build/C/man3/sem_open.3:41 build/C/man7/sem_overview.7:29 build/C/man3/sem_post.3:37 build/C/man3/sem_unlink.3:37 build/C/man3/sem_wait.3:49 build/C/man2/semctl.2:52 build/C/man2/semget.2:49 build/C/man2/semop.2:57
84 #: build/C/man3/sem_close.3:43
86 "B<sem_close>() closes the named semaphore referred to by I<sem>, allowing "
87 "any resources that the system has allocated to the calling process for this "
88 "semaphore to be freed."
92 #: build/C/man3/sem_close.3:43 build/C/man3/sem_destroy.3:55 build/C/man3/sem_getvalue.3:54 build/C/man3/sem_init.3:77 build/C/man3/sem_open.3:104 build/C/man3/sem_post.3:45 build/C/man3/sem_unlink.3:44 build/C/man3/sem_wait.3:108 build/C/man2/semctl.2:340 build/C/man2/semget.2:157 build/C/man2/semop.2:309
98 #: build/C/man3/sem_close.3:49
100 "On success B<sem_close>() returns 0; on error, -1 is returned, with "
101 "I<errno> set to indicate the error."
105 #: build/C/man3/sem_close.3:49 build/C/man3/sem_destroy.3:61 build/C/man3/sem_getvalue.3:60 build/C/man3/sem_init.3:83 build/C/man3/sem_open.3:116 build/C/man3/sem_post.3:52 build/C/man3/sem_unlink.3:50 build/C/man3/sem_wait.3:114 build/C/man2/semctl.2:387 build/C/man2/semget.2:163 build/C/man2/semop.2:319
111 #: build/C/man3/sem_close.3:50 build/C/man3/sem_destroy.3:62 build/C/man3/sem_getvalue.3:61 build/C/man3/sem_init.3:84 build/C/man3/sem_open.3:132 build/C/man3/sem_open.3:137 build/C/man3/sem_post.3:53 build/C/man3/sem_wait.3:119 build/C/man3/sem_wait.3:133 build/C/man2/semctl.2:420 build/C/man2/semget.2:188 build/C/man2/semop.2:367
117 #: build/C/man3/sem_close.3:54 build/C/man3/sem_destroy.3:66 build/C/man3/sem_getvalue.3:65 build/C/man3/sem_post.3:57 build/C/man3/sem_wait.3:123
118 msgid "I<sem> is not a valid semaphore."
122 #: build/C/man3/sem_close.3:54 build/C/man3/sem_destroy.3:66 build/C/man3/sem_getvalue.3:65 build/C/man3/sem_init.3:95 build/C/man3/sem_open.3:170 build/C/man7/sem_overview.7:138 build/C/man3/sem_post.3:61 build/C/man3/sem_unlink.3:62 build/C/man3/sem_wait.3:143 build/C/man2/semctl.2:462 build/C/man2/semget.2:219 build/C/man2/semop.2:397
124 msgid "CONFORMING TO"
128 #: build/C/man3/sem_close.3:56 build/C/man3/sem_destroy.3:68 build/C/man3/sem_getvalue.3:67 build/C/man3/sem_init.3:97 build/C/man3/sem_open.3:172 build/C/man7/sem_overview.7:140 build/C/man3/sem_post.3:63 build/C/man3/sem_unlink.3:64 build/C/man3/sem_wait.3:145
129 msgid "POSIX.1-2001."
133 #: build/C/man3/sem_close.3:56 build/C/man3/sem_destroy.3:68 build/C/man3/sem_getvalue.3:67 build/C/man3/sem_init.3:97 build/C/man7/sem_overview.7:140 build/C/man3/sem_post.3:63 build/C/man3/sem_wait.3:145 build/C/man2/semctl.2:476 build/C/man2/semget.2:223 build/C/man2/semop.2:400
139 #: build/C/man3/sem_close.3:60
141 "All open named semaphores are automatically closed on process termination, "
142 "or upon B<execve>(2)."
146 #: build/C/man3/sem_close.3:60 build/C/man3/sem_destroy.3:74 build/C/man3/sem_getvalue.3:71 build/C/man3/sem_init.3:102 build/C/man3/sem_open.3:172 build/C/man7/sem_overview.7:152 build/C/man3/sem_post.3:70 build/C/man3/sem_unlink.3:64 build/C/man3/sem_wait.3:262 build/C/man2/semctl.2:536 build/C/man2/semget.2:294 build/C/man2/semop.2:536
152 #: build/C/man3/sem_close.3:67
154 "B<sem_getvalue>(3), B<sem_open>(3), B<sem_post>(3), B<sem_unlink>(3), "
155 "B<sem_wait>(3), B<sem_overview>(7)"
159 #: build/C/man3/sem_close.3:67 build/C/man3/sem_destroy.3:79 build/C/man3/sem_getvalue.3:75 build/C/man3/sem_init.3:107 build/C/man3/sem_open.3:179 build/C/man7/sem_overview.7:162 build/C/man3/sem_post.3:74 build/C/man3/sem_unlink.3:70 build/C/man3/sem_wait.3:268 build/C/man2/semctl.2:543 build/C/man2/semget.2:301 build/C/man2/semop.2:545
165 #: build/C/man3/sem_close.3:74 build/C/man3/sem_destroy.3:86 build/C/man3/sem_getvalue.3:82 build/C/man3/sem_init.3:114 build/C/man3/sem_open.3:186 build/C/man7/sem_overview.7:169 build/C/man3/sem_post.3:81 build/C/man3/sem_unlink.3:77 build/C/man3/sem_wait.3:275 build/C/man2/semctl.2:550 build/C/man2/semget.2:308 build/C/man2/semop.2:552
167 "This page is part of release 3.54 of the Linux I<man-pages> project. A "
168 "description of the project, and information about reporting bugs, can be "
169 "found at \\%http://www.kernel.org/doc/man-pages/."
173 #: build/C/man3/sem_destroy.3:26
179 #: build/C/man3/sem_destroy.3:29
180 msgid "sem_destroy - destroy an unnamed semaphore"
184 #: build/C/man3/sem_destroy.3:34
186 msgid "B<int sem_destroy(sem_t *>I<sem>B<);>\n"
190 #: build/C/man3/sem_destroy.3:41
192 "B<sem_destroy>() destroys the unnamed semaphore at the address pointed to "
197 #: build/C/man3/sem_destroy.3:46
199 "Only a semaphore that has been initialized by B<sem_init>(3) should be "
200 "destroyed using B<sem_destroy>()."
204 #: build/C/man3/sem_destroy.3:51
206 "Destroying a semaphore that other processes or threads are currently blocked "
207 "on (in B<sem_wait>(3)) produces undefined behavior."
211 #: build/C/man3/sem_destroy.3:55
213 "Using a semaphore that has been destroyed produces undefined results, until "
214 "the semaphore has been reinitialized using B<sem_init>(3)."
218 #: build/C/man3/sem_destroy.3:61
220 "B<sem_destroy>() returns 0 on success; on error, -1 is returned, and "
221 "I<errno> is set to indicate the error."
224 #. But not on NPTL, where sem_destroy () is a no-op..
226 #: build/C/man3/sem_destroy.3:74
228 "An unnamed semaphore should be destroyed with B<sem_destroy>() before the "
229 "memory in which it is located is deallocated. Failure to do this can result "
230 "in resource leaks on some implementations."
234 #: build/C/man3/sem_destroy.3:79
235 msgid "B<sem_init>(3), B<sem_post>(3), B<sem_wait>(3), B<sem_overview>(7)"
239 #: build/C/man3/sem_getvalue.3:26
245 #: build/C/man3/sem_getvalue.3:29
246 msgid "sem_getvalue - get the value of a semaphore"
250 #: build/C/man3/sem_getvalue.3:34
252 msgid "B<int sem_getvalue(sem_t *>I<sem>B<, int *>I<sval>B<);>\n"
256 #: build/C/man3/sem_getvalue.3:43
258 "B<sem_getvalue>() places the current value of the semaphore pointed to "
259 "I<sem> into the integer pointed to by I<sval>."
263 #: build/C/man3/sem_getvalue.3:54
265 "If one or more processes or threads are blocked waiting to lock the "
266 "semaphore with B<sem_wait>(3), POSIX.1-2001 permits two possibilities for "
267 "the value returned in I<sval>: either 0 is returned; or a negative number "
268 "whose absolute value is the count of the number of processes and threads "
269 "currently blocked in B<sem_wait>(3). Linux adopts the former behavior."
273 #: build/C/man3/sem_getvalue.3:60
275 "B<sem_getvalue>() returns 0 on success; on error, -1 is returned and "
276 "I<errno> is set to indicate the error."
280 #: build/C/man3/sem_getvalue.3:71
282 "The value of the semaphore may already have changed by the time "
283 "B<sem_getvalue>() returns."
287 #: build/C/man3/sem_getvalue.3:75
288 msgid "B<sem_post>(3), B<sem_wait>(3), B<sem_overview>(7)"
292 #: build/C/man3/sem_init.3:26
298 #: build/C/man3/sem_init.3:29
299 msgid "sem_init - initialize an unnamed semaphore"
303 #: build/C/man3/sem_init.3:34
306 "B<int sem_init(sem_t *>I<sem>B<, int >I<pshared>B<, unsigned int "
311 #: build/C/man3/sem_init.3:44
313 "B<sem_init>() initializes the unnamed semaphore at the address pointed to "
314 "by I<sem>. The I<value> argument specifies the initial value for the "
319 #: build/C/man3/sem_init.3:49
321 "The I<pshared> argument indicates whether this semaphore is to be shared "
322 "between the threads of a process, or between processes."
326 #: build/C/man3/sem_init.3:57
328 "If I<pshared> has the value 0, then the semaphore is shared between the "
329 "threads of a process, and should be located at some address that is visible "
330 "to all threads (e.g., a global variable, or a variable allocated dynamically "
335 #: build/C/man3/sem_init.3:74
337 "If I<pshared> is nonzero, then the semaphore is shared between processes, "
338 "and should be located in a region of shared memory (see B<shm_open>(3), "
339 "B<mmap>(2), and B<shmget>(2)). (Since a child created by B<fork>(2) "
340 "inherits its parent's memory mappings, it can also access the semaphore.) "
341 "Any process that can access the shared memory region can operate on the "
342 "semaphore using B<sem_post>(3), B<sem_wait>(3), etc."
346 #: build/C/man3/sem_init.3:77
348 "Initializing a semaphore that has already been initialized results in "
349 "undefined behavior."
353 #: build/C/man3/sem_init.3:83
355 "B<sem_init>() returns 0 on success; on error, -1 is returned, and I<errno> "
356 "is set to indicate the error."
360 #: build/C/man3/sem_init.3:89
361 msgid "I<value> exceeds B<SEM_VALUE_MAX>."
365 #: build/C/man3/sem_init.3:89
371 #: build/C/man3/sem_init.3:95
373 "I<pshared> is nonzero, but the system does not support process-shared "
374 "semaphores (see B<sem_overview>(7))."
378 #: build/C/man3/sem_init.3:102
380 "Bizarrely, POSIX.1-2001 does not specify the value that should be returned "
381 "by a successful call to B<sem_init>(). POSIX.1-2008 rectifies this, "
382 "specifying the zero return on success."
386 #: build/C/man3/sem_init.3:107
387 msgid "B<sem_destroy>(3), B<sem_post>(3), B<sem_wait>(3), B<sem_overview>(7)"
391 #: build/C/man3/sem_open.3:26
397 #: build/C/man3/sem_open.3:29
398 msgid "sem_open - initialize and open a named semaphore"
402 #: build/C/man3/sem_open.3:34
405 "B<#include E<lt>fcntl.hE<gt>> /* For O_* constants */\n"
406 "B<#include E<lt>sys/stat.hE<gt>> /* For mode constants */\n"
407 "B<#include E<lt>semaphore.hE<gt>>\n"
411 #: build/C/man3/sem_open.3:38
414 "B<sem_t *sem_open(const char *>I<name>B<, int >I<oflag>B<);>\n"
415 "B<sem_t *sem_open(const char *>I<name>B<, int >I<oflag>B<, >\n"
416 "B< mode_t >I<mode>B<, unsigned int >I<value>B<);>\n"
420 #: build/C/man3/sem_open.3:50
422 "B<sem_open>() creates a new POSIX semaphore or opens an existing "
423 "semaphore. The semaphore is identified by I<name>. For details of the "
424 "construction of I<name>, see B<sem_overview>(7)."
427 #. In reality the filesystem IDs are used on Linux.
429 #: build/C/man3/sem_open.3:76
431 "The I<oflag> argument specifies flags that control the operation of the "
432 "call. (Definitions of the flags values can be obtained by including "
433 "I<E<lt>fcntl.hE<gt>>.) If B<O_CREAT> is specified in I<oflag>, then the "
434 "semaphore is created if it does not already exist. The owner (user ID) of "
435 "the semaphore is set to the effective user ID of the calling process. The "
436 "group ownership (group ID) is set to the effective group ID of the calling "
437 "process. If both B<O_CREAT> and B<O_EXCL> are specified in I<oflag>, then "
438 "an error is returned if a semaphore with the given I<name> already exists."
442 #: build/C/man3/sem_open.3:104
444 "If B<O_CREAT> is specified in I<oflag>, then two additional arguments must "
445 "be supplied. The I<mode> argument specifies the permissions to be placed on "
446 "the new semaphore, as for B<open>(2). (Symbolic definitions for the "
447 "permissions bits can be obtained by including I<E<lt>sys/stat.hE<gt>>.) The "
448 "permissions settings are masked against the process umask. Both read and "
449 "write permission should be granted to each class of user that will access "
450 "the semaphore. The I<value> argument specifies the initial value for the "
451 "new semaphore. If B<O_CREAT> is specified, and a semaphore with the given "
452 "I<name> already exists, then I<mode> and I<value> are ignored."
456 #: build/C/man3/sem_open.3:116
458 "On success, B<sem_open>() returns the address of the new semaphore; this "
459 "address is used when calling other semaphore-related functions. On error, "
460 "B<sem_open>() returns B<SEM_FAILED>, with I<errno> set to indicate the "
465 #: build/C/man3/sem_open.3:117 build/C/man3/sem_unlink.3:51 build/C/man2/semctl.2:391 build/C/man2/semget.2:167 build/C/man2/semop.2:331
471 #: build/C/man3/sem_open.3:121
472 msgid "The semaphore exists, but the caller does not have permission to open it."
476 #: build/C/man3/sem_open.3:121 build/C/man2/semget.2:175
482 #: build/C/man3/sem_open.3:132
484 "Both B<O_CREAT> and B<O_EXCL> were specified in I<oflag>, but a semaphore "
485 "with this I<name> already exists."
489 #: build/C/man3/sem_open.3:137
490 msgid "I<value> was greater than B<SEM_VALUE_MAX>."
494 #: build/C/man3/sem_open.3:141
495 msgid "I<name> consists of just \"/\", followed by no other characters."
499 #: build/C/man3/sem_open.3:141
505 #: build/C/man3/sem_open.3:144
506 msgid "The process already has the maximum number of files and open."
510 #: build/C/man3/sem_open.3:144 build/C/man3/sem_unlink.3:54
512 msgid "B<ENAMETOOLONG>"
516 #: build/C/man3/sem_open.3:148 build/C/man3/sem_unlink.3:58
517 msgid "I<name> was too long."
521 #: build/C/man3/sem_open.3:148
527 #: build/C/man3/sem_open.3:151
528 msgid "The system limit on the total number of open files has been reached."
532 #: build/C/man3/sem_open.3:151 build/C/man3/sem_unlink.3:58 build/C/man2/semget.2:199
537 #. this error can occur if we have a name of the (nonportable) form
538 #. /dir/name, and the directory /dev/shm/dir does not exist.
540 #: build/C/man3/sem_open.3:167
542 "The B<O_CREAT> flag was not specified in I<oflag> and no semaphore with this "
543 "I<name> exists; or, B<O_CREAT> was specified, but I<name> wasn't well "
548 #: build/C/man3/sem_open.3:167 build/C/man2/semget.2:207 build/C/man2/semop.2:374
554 #: build/C/man3/sem_open.3:170
555 msgid "Insufficient memory."
559 #: build/C/man3/sem_open.3:179
561 "B<sem_close>(3), B<sem_getvalue>(3), B<sem_post>(3), B<sem_unlink>(3), "
562 "B<sem_wait>(3), B<sem_overview>(7)"
566 #: build/C/man7/sem_overview.7:26
572 #: build/C/man7/sem_overview.7:29
573 msgid "sem_overview - overview of POSIX semaphores"
577 #: build/C/man7/sem_overview.7:31
578 msgid "POSIX semaphores allow processes and threads to synchronize their actions."
582 #: build/C/man7/sem_overview.7:41
584 "A semaphore is an integer whose value is never allowed to fall below zero. "
585 "Two operations can be performed on semaphores: increment the semaphore value "
586 "by one (B<sem_post>(3)); and decrement the semaphore value by one "
587 "(B<sem_wait>(3)). If the value of a semaphore is currently zero, then a "
588 "B<sem_wait>(3) operation will block until the value becomes greater than "
593 #: build/C/man7/sem_overview.7:44
594 msgid "POSIX semaphores come in two forms: named semaphores and unnamed semaphores."
598 #: build/C/man7/sem_overview.7:44
600 msgid "B<Named semaphores>"
603 #. glibc allows the initial slash to be omitted, and makes
604 #. multiple initial slashes equivalent to a single slash.
605 #. This differs from the implementation of POSIX message queues.
606 #. glibc allows subdirectory components in the name, in which
607 #. case the subdirectory tree must exist under /dev/shm, and
608 #. the fist subdirectory component must exist as the name
609 #. sem.name, and all of the subdirectory components must allow the
610 #. required permissions if a user wants to create a semaphore
611 #. object in a subdirectory.
613 #: build/C/man7/sem_overview.7:64
615 "A named semaphore is identified by a name of the form I</somename>; that is, "
616 "a null-terminated string of up to B<NAME_MAX>I<-4> (i.e., 251) characters "
617 "consisting of an initial slash, followed by one or more characters, none of "
618 "which are slashes. Two processes can operate on the same named semaphore by "
619 "passing the same name to B<sem_open>(3)."
623 #: build/C/man7/sem_overview.7:79
625 "The B<sem_open>(3) function creates a new named semaphore or opens an "
626 "existing named semaphore. After the semaphore has been opened, it can be "
627 "operated on using B<sem_post>(3) and B<sem_wait>(3). When a process has "
628 "finished using the semaphore, it can use B<sem_close>(3) to close the "
629 "semaphore. When all processes have finished using the semaphore, it can be "
630 "removed from the system using B<sem_unlink>(3)."
634 #: build/C/man7/sem_overview.7:79
636 msgid "B<Unnamed semaphores (memory-based semaphores)>"
640 #: build/C/man7/sem_overview.7:94
642 "An unnamed semaphore does not have a name. Instead the semaphore is placed "
643 "in a region of memory that is shared between multiple threads (a "
644 "I<thread-shared semaphore>) or processes (a I<process-shared semaphore>). "
645 "A thread-shared semaphore is placed in an area of memory shared between the "
646 "threads of a process, for example, a global variable. A process-shared "
647 "semaphore must be placed in a shared memory region (e.g., a System V shared "
648 "memory segment created using B<shmget>(2), or a POSIX shared memory object "
649 "built created using B<shm_open>(3))."
653 #: build/C/man7/sem_overview.7:105
655 "Before being used, an unnamed semaphore must be initialized using "
656 "B<sem_init>(3). It can then be operated on using B<sem_post>(3) and "
657 "B<sem_wait>(3). When the semaphore is no longer required, and before the "
658 "memory in which it is located is deallocated, the semaphore should be "
659 "destroyed using B<sem_destroy>(3)."
663 #: build/C/man7/sem_overview.7:108
665 "The remainder of this section describes some specific details of the Linux "
666 "implementation of POSIX semaphores."
670 #: build/C/man7/sem_overview.7:108
676 #: build/C/man7/sem_overview.7:114
678 "Prior to kernel 2.6, Linux supported only unnamed, thread-shared "
679 "semaphores. On a system with Linux 2.6 and a glibc that provides the NPTL "
680 "threading implementation, a complete implementation of POSIX semaphores is "
685 #: build/C/man7/sem_overview.7:114
691 #: build/C/man7/sem_overview.7:119
693 "POSIX named semaphores have kernel persistence: if not removed by "
694 "B<sem_unlink>(3), a semaphore will exist until the system is shut down."
698 #: build/C/man7/sem_overview.7:119
704 #: build/C/man7/sem_overview.7:124
706 "Programs using the POSIX semaphores API must be compiled with I<cc -pthread> "
707 "to link against the real-time library, I<librt>."
711 #: build/C/man7/sem_overview.7:124
713 msgid "Accessing named semaphores via the filesystem"
717 #: build/C/man7/sem_overview.7:135
719 "On Linux, named semaphores are created in a virtual filesystem, normally "
720 "mounted under I</dev/shm>, with names of the form B<sem.>I<somename>. (This "
721 "is the reason that semaphore names are limited to B<NAME_MAX>I<-4> rather "
722 "than B<NAME_MAX> characters.)"
726 #: build/C/man7/sem_overview.7:138
728 "Since Linux 2.6.19, ACLs can be placed on files under this directory, to "
729 "control object permissions on a per-user and per-group basis."
733 #: build/C/man7/sem_overview.7:149
735 "System V semaphores (B<semget>(2), B<semop>(2), etc.) are an older semaphore "
736 "API. POSIX semaphores provide a simpler, and better designed interface than "
737 "System V semaphores; on the other hand POSIX semaphores are less widely "
738 "available (especially on older systems) than System V semaphores."
742 #: build/C/man7/sem_overview.7:149 build/C/man3/sem_post.3:67 build/C/man3/sem_wait.3:153 build/C/man2/semop.2:511
748 #: build/C/man7/sem_overview.7:152
750 "An example of the use of various POSIX semaphore functions is shown in "
755 #: build/C/man7/sem_overview.7:162
757 "B<sem_close>(3), B<sem_destroy>(3), B<sem_getvalue>(3), B<sem_init>(3), "
758 "B<sem_open>(3), B<sem_post>(3), B<sem_unlink>(3), B<sem_wait>(3), "
763 #: build/C/man3/sem_post.3:26
769 #: build/C/man3/sem_post.3:29
770 msgid "sem_post - unlock a semaphore"
774 #: build/C/man3/sem_post.3:34
776 msgid "B<int sem_post(sem_t *>I<sem>B<);>\n"
780 #: build/C/man3/sem_post.3:45
782 "B<sem_post>() increments (unlocks) the semaphore pointed to by I<sem>. If "
783 "the semaphore's value consequently becomes greater than zero, then another "
784 "process or thread blocked in a B<sem_wait>(3) call will be woken up and "
785 "proceed to lock the semaphore."
789 #: build/C/man3/sem_post.3:52
791 "B<sem_post>() returns 0 on success; on error, the value of the semaphore is "
792 "left unchanged, -1 is returned, and I<errno> is set to indicate the error."
796 #: build/C/man3/sem_post.3:57
801 #. Added in POSIX.1-2008 TC1 (Austin Interpretation 213)
803 #: build/C/man3/sem_post.3:61
804 msgid "The maximum allowable value for a semaphore would be exceeded."
808 #: build/C/man3/sem_post.3:67
810 "B<sem_post>() is async-signal-safe: it may be safely called within a signal "
815 #: build/C/man3/sem_post.3:70
816 msgid "See B<sem_wait>(3)."
820 #: build/C/man3/sem_post.3:74
821 msgid "B<sem_getvalue>(3), B<sem_wait>(3), B<sem_overview>(7)"
825 #: build/C/man3/sem_unlink.3:26
831 #: build/C/man3/sem_unlink.3:29
832 msgid "sem_unlink - remove a named semaphore"
836 #: build/C/man3/sem_unlink.3:34
838 msgid "B<int sem_unlink(const char *>I<name>B<);>\n"
842 #: build/C/man3/sem_unlink.3:44
844 "B<sem_unlink>() removes the named semaphore referred to by I<name>. The "
845 "semaphore name is removed immediately. The semaphore is destroyed once all "
846 "other processes that have the semaphore open close it."
850 #: build/C/man3/sem_unlink.3:50
852 "On success B<sem_unlink>() returns 0; on error, -1 is returned, with "
853 "I<errno> set to indicate the error."
857 #: build/C/man3/sem_unlink.3:54
858 msgid "The caller does not have permission to unlink this semaphore."
862 #: build/C/man3/sem_unlink.3:62
863 msgid "There is no semaphore with the given I<name>."
867 #: build/C/man3/sem_unlink.3:70
869 "B<sem_getvalue>(3), B<sem_open>(3), B<sem_post>(3), B<sem_wait>(3), "
874 #: build/C/man3/sem_wait.3:26
880 #: build/C/man3/sem_wait.3:29
881 msgid "sem_wait, sem_timedwait, sem_trywait - lock a semaphore"
885 #: build/C/man3/sem_wait.3:34
887 msgid "B<int sem_wait(sem_t *>I<sem>B<);>\n"
891 #: build/C/man3/sem_wait.3:36
893 msgid "B<int sem_trywait(sem_t *>I<sem>B<);>\n"
897 #: build/C/man3/sem_wait.3:38
900 "B<int sem_timedwait(sem_t *>I<sem>B<, const struct timespec "
901 "*>I<abs_timeout>B<);>\n"
905 #: build/C/man3/sem_wait.3:45 build/C/man2/semop.2:53
906 msgid "Feature Test Macro Requirements for glibc (see B<feature_test_macros>(7)):"
910 #: build/C/man3/sem_wait.3:49
912 "B<sem_timedwait>(): _POSIX_C_SOURCE\\ E<gt>=\\ 200112L || _XOPEN_SOURCE\\ "
917 #: build/C/man3/sem_wait.3:59
919 "B<sem_wait>() decrements (locks) the semaphore pointed to by I<sem>. If "
920 "the semaphore's value is greater than zero, then the decrement proceeds, and "
921 "the function returns, immediately. If the semaphore currently has the value "
922 "zero, then the call blocks until either it becomes possible to perform the "
923 "decrement (i.e., the semaphore value rises above zero), or a signal handler "
924 "interrupts the call."
928 #: build/C/man3/sem_wait.3:69
930 "B<sem_trywait>() is the same as B<sem_wait>(), except that if the decrement "
931 "cannot be immediately performed, then call returns an error (I<errno> set to "
932 "B<EAGAIN>) instead of blocking."
936 #: build/C/man3/sem_wait.3:82
938 "B<sem_timedwait>() is the same as B<sem_wait>(), except that I<abs_timeout> "
939 "specifies a limit on the amount of time that the call should block if the "
940 "decrement cannot be immediately performed. The I<abs_timeout> argument "
941 "points to a structure that specifies an absolute timeout in seconds and "
942 "nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). This "
943 "structure is defined as follows:"
947 #: build/C/man3/sem_wait.3:89
950 "struct timespec {\n"
951 " time_t tv_sec; /* Seconds */\n"
952 " long tv_nsec; /* Nanoseconds [0 .. 999999999] */\n"
957 #: build/C/man3/sem_wait.3:100
959 "If the timeout has already expired by the time of the call, and the "
960 "semaphore could not be locked immediately, then B<sem_timedwait>() fails "
961 "with a timeout error (I<errno> set to B<ETIMEDOUT>)."
965 #: build/C/man3/sem_wait.3:108
967 "If the operation can be performed immediately, then B<sem_timedwait>() "
968 "never fails with a timeout error, regardless of the value of "
969 "I<abs_timeout>. Furthermore, the validity of I<abs_timeout> is not checked "
974 #: build/C/man3/sem_wait.3:114
976 "All of these functions return 0 on success; on error, the value of the "
977 "semaphore is left unchanged, -1 is returned, and I<errno> is set to indicate "
982 #: build/C/man3/sem_wait.3:115 build/C/man2/semop.2:363
988 #: build/C/man3/sem_wait.3:119
989 msgid "The call was interrupted by a signal handler; see B<signal>(7)."
993 #: build/C/man3/sem_wait.3:126
994 msgid "The following additional error can occur for B<sem_trywait>():"
998 #: build/C/man3/sem_wait.3:126 build/C/man2/semop.2:338
1004 #: build/C/man3/sem_wait.3:130
1006 "The operation could not be performed without blocking (i.e., the semaphore "
1007 "currently has the value zero)."
1011 #: build/C/man3/sem_wait.3:133
1012 msgid "The following additional errors can occur for B<sem_timedwait>():"
1016 #: build/C/man3/sem_wait.3:138
1018 "The value of I<abs_timeout.tv_nsecs> is less than 0, or greater than or "
1019 "equal to 1000 million."
1023 #: build/C/man3/sem_wait.3:138
1025 msgid "B<ETIMEDOUT>"
1028 #. POSIX.1-2001 also allows EDEADLK -- "A deadlock condition
1029 #. was detected", but this does not occur on Linux(?).
1031 #: build/C/man3/sem_wait.3:143
1032 msgid "The call timed out before the semaphore could be locked."
1035 #. sem_wait() is always interrupted on most other implementations,
1036 #. but on FreeBSD 5.4 SA_RESTART does cause restarting.
1038 #: build/C/man3/sem_wait.3:153
1040 "A signal handler always interrupts a blocked call to one of these functions, "
1041 "regardless of the use of the B<sigaction>(2) B<SA_RESTART> flag."
1045 #: build/C/man3/sem_wait.3:172
1047 "The (somewhat trivial) program shown below operates on an unnamed "
1048 "semaphore. The program expects two command-line arguments. The first "
1049 "argument specifies a seconds value that is used to set an alarm timer to "
1050 "generate a B<SIGALRM> signal. This handler performs a B<sem_post>(3) to "
1051 "increment the semaphore that is being waited on in I<main()> using "
1052 "B<sem_timedwait>(). The second command-line argument specifies the length "
1053 "of the timeout, in seconds, for B<sem_timedwait>(). The following shows "
1054 "what happens on two different runs of the program:"
1058 #: build/C/man3/sem_wait.3:182
1061 "$B< ./a.out 2 3>\n"
1062 "About to call sem_timedwait()\n"
1063 "sem_post() from handler\n"
1064 "sem_timedwait() succeeded\n"
1065 "$B< ./a.out 2 1>\n"
1066 "About to call sem_timedwait()\n"
1067 "sem_timedwait() timed out\n"
1071 #: build/C/man3/sem_wait.3:184
1073 msgid "Program source"
1077 #: build/C/man3/sem_wait.3:195
1080 "#include E<lt>unistd.hE<gt>\n"
1081 "#include E<lt>stdio.hE<gt>\n"
1082 "#include E<lt>stdlib.hE<gt>\n"
1083 "#include E<lt>semaphore.hE<gt>\n"
1084 "#include E<lt>time.hE<gt>\n"
1085 "#include E<lt>assert.hE<gt>\n"
1086 "#include E<lt>errno.hE<gt>\n"
1087 "#include E<lt>signal.hE<gt>\n"
1091 #: build/C/man3/sem_wait.3:197
1093 msgid "sem_t sem;\n"
1097 #: build/C/man3/sem_wait.3:200
1100 "#define handle_error(msg) \\e\n"
1101 " do { perror(msg); exit(EXIT_FAILURE); } while (0)\n"
1105 #: build/C/man3/sem_wait.3:210
1109 "handler(int sig)\n"
1111 " write(STDOUT_FILENO, \"sem_post() from handler\\en\", 24);\n"
1112 " if (sem_post(&sem) == -1) {\n"
1113 " write(STDERR_FILENO, \"sem_post() failed\\en\", 18);\n"
1114 " _exit(EXIT_FAILURE);\n"
1120 #: build/C/man3/sem_wait.3:217
1124 "main(int argc, char *argv[])\n"
1126 " struct sigaction sa;\n"
1127 " struct timespec ts;\n"
1132 #: build/C/man3/sem_wait.3:223
1135 " if (argc != 3) {\n"
1136 " fprintf(stderr, \"Usage: %s E<lt>alarm-secsE<gt> "
1137 "E<lt>wait-secsE<gt>\\en\",\n"
1139 " exit(EXIT_FAILURE);\n"
1144 #: build/C/man3/sem_wait.3:226
1147 " if (sem_init(&sem, 0, 0) == -1)\n"
1148 " handle_error(\"sem_init\");\n"
1152 #: build/C/man3/sem_wait.3:228
1154 msgid " /* Establish SIGALRM handler; set alarm timer using argv[1] */\n"
1158 #: build/C/man3/sem_wait.3:234
1161 " sa.sa_handler = handler;\n"
1162 " sigemptyset(&sa.sa_mask);\n"
1163 " sa.sa_flags = 0;\n"
1164 " if (sigaction(SIGALRM, &sa, NULL) == -1)\n"
1165 " handle_error(\"sigaction\");\n"
1169 #: build/C/man3/sem_wait.3:236
1171 msgid " alarm(atoi(argv[1]));\n"
1175 #: build/C/man3/sem_wait.3:239
1178 " /* Calculate relative interval as current time plus\n"
1179 " number of seconds given argv[2] */\n"
1183 #: build/C/man3/sem_wait.3:242
1186 " if (clock_gettime(CLOCK_REALTIME, &ts) == -1)\n"
1187 " handle_error(\"clock_gettime\");\n"
1191 #: build/C/man3/sem_wait.3:244
1193 msgid " ts.tv_sec += atoi(argv[2]);\n"
1197 #: build/C/man3/sem_wait.3:248
1200 " printf(\"main() about to call sem_timedwait()\\en\");\n"
1201 " while ((s = sem_timedwait(&sem, &ts)) == -1 && errno == EINTR)\n"
1202 " continue; /* Restart if interrupted by handler */\n"
1206 #: build/C/man3/sem_wait.3:250
1208 msgid " /* Check what happened */\n"
1212 #: build/C/man3/sem_wait.3:258
1216 " if (errno == ETIMEDOUT)\n"
1217 " printf(\"sem_timedwait() timed out\\en\");\n"
1219 " perror(\"sem_timedwait\");\n"
1221 " printf(\"sem_timedwait() succeeded\\en\");\n"
1225 #: build/C/man3/sem_wait.3:261
1228 " exit((s == 0) ? EXIT_SUCCESS : EXIT_FAILURE);\n"
1233 #: build/C/man3/sem_wait.3:268
1235 "B<clock_gettime>(2), B<sem_getvalue>(3), B<sem_post>(3), B<sem_overview>(7), "
1240 #: build/C/man2/semctl.2:41
1246 #: build/C/man2/semctl.2:41
1252 #: build/C/man2/semctl.2:44
1253 msgid "semctl - System V semaphore control operations"
1257 #: build/C/man2/semctl.2:49 build/C/man2/semget.2:44 build/C/man2/semop.2:43
1260 "B<#include E<lt>sys/types.hE<gt>>\n"
1261 "B<#include E<lt>sys/ipc.hE<gt>>\n"
1262 "B<#include E<lt>sys/sem.hE<gt>>\n"
1266 #: build/C/man2/semctl.2:51
1268 msgid "B<int semctl(int >I<semid>B<, int >I<semnum>B<, int >I<cmd>B<, ...);>\n"
1272 #: build/C/man2/semctl.2:62
1274 "B<semctl>() performs the control operation specified by I<cmd> on the "
1275 "System V semaphore set identified by I<semid>, or on the I<semnum>-th "
1276 "semaphore of that set. (The semaphores in a set are numbered starting at "
1281 #: build/C/man2/semctl.2:68
1283 "This function has three or four arguments, depending on I<cmd>. When there "
1284 "are four, the fourth has the type I<union semun>. The I<calling program> "
1285 "must define this union as follows:"
1289 #: build/C/man2/semctl.2:78
1293 " int val; /* Value for SETVAL */\n"
1294 " struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */\n"
1295 " unsigned short *array; /* Array for GETALL, SETALL */\n"
1296 " struct seminfo *__buf; /* Buffer for IPC_INFO\n"
1297 " (Linux-specific) */\n"
1302 #: build/C/man2/semctl.2:84
1304 "The I<semid_ds> data structure is defined in I<E<lt>sys/sem.hE<gt>> as "
1309 #: build/C/man2/semctl.2:93
1312 "struct semid_ds {\n"
1313 " struct ipc_perm sem_perm; /* Ownership and permissions */\n"
1314 " time_t sem_otime; /* Last semop time */\n"
1315 " time_t sem_ctime; /* Last change time */\n"
1316 " unsigned long sem_nsems; /* No. of semaphores in set */\n"
1321 #: build/C/man2/semctl.2:101
1323 "The I<ipc_perm> structure is defined as follows (the highlighted fields are "
1324 "settable using B<IPC_SET>):"
1328 #: build/C/man2/semctl.2:113
1331 "struct ipc_perm {\n"
1332 " key_t __key; /* Key supplied to semget(2) */\n"
1333 " uid_t B<uid>; /* Effective UID of owner */\n"
1334 " gid_t B<gid>; /* Effective GID of owner */\n"
1335 " uid_t cuid; /* Effective UID of creator */\n"
1336 " gid_t cgid; /* Effective GID of creator */\n"
1337 " unsigned short B<mode>; /* Permissions */\n"
1338 " unsigned short __seq; /* Sequence number */\n"
1343 #: build/C/man2/semctl.2:119
1344 msgid "Valid values for I<cmd> are:"
1348 #: build/C/man2/semctl.2:119
1354 #: build/C/man2/semctl.2:131
1356 "Copy information from the kernel data structure associated with I<semid> "
1357 "into the I<semid_ds> structure pointed to by I<arg.buf>. The argument "
1358 "I<semnum> is ignored. The calling process must have read permission on the "
1363 #: build/C/man2/semctl.2:131
1369 #: build/C/man2/semctl.2:154
1371 "Write the values of some members of the I<semid_ds> structure pointed to by "
1372 "I<arg.buf> to the kernel data structure associated with this semaphore set, "
1373 "updating also its I<sem_ctime> member. The following members of the "
1374 "structure are updated: I<sem_perm.uid>, I<sem_perm.gid>, and (the least "
1375 "significant 9 bits of) I<sem_perm.mode>. The effective UID of the calling "
1376 "process must match the owner (I<sem_perm.uid>) or creator "
1377 "(I<sem_perm.cuid>) of the semaphore set, or the caller must be privileged. "
1378 "The argument I<semnum> is ignored."
1382 #: build/C/man2/semctl.2:154
1388 #: build/C/man2/semctl.2:169
1390 "Immediately remove the semaphore set, awakening all processes blocked in "
1391 "B<semop>(2) calls on the set (with an error return and I<errno> set to "
1392 "B<EIDRM>). The effective user ID of the calling process must match the "
1393 "creator or owner of the semaphore set, or the caller must be privileged. "
1394 "The argument I<semnum> is ignored."
1398 #: build/C/man2/semctl.2:169
1400 msgid "B<IPC_INFO> (Linux-specific)"
1404 #: build/C/man2/semctl.2:181
1406 "Returns information about system-wide semaphore limits and parameters in the "
1407 "structure pointed to by I<arg.__buf>. This structure is of type I<seminfo>, "
1408 "defined in I<E<lt>sys/sem.hE<gt>> if the B<_GNU_SOURCE> feature test macro "
1413 #: build/C/man2/semctl.2:203
1416 "struct seminfo {\n"
1417 " int semmap; /* Number of entries in semaphore\n"
1418 " map; unused within kernel */\n"
1419 " int semmni; /* Maximum number of semaphore sets */\n"
1420 " int semmns; /* Maximum number of semaphores in all\n"
1421 " semaphore sets */\n"
1422 " int semmnu; /* System-wide maximum number of undo\n"
1423 " structures; unused within kernel */\n"
1424 " int semmsl; /* Maximum number of semaphores in a\n"
1426 " int semopm; /* Maximum number of operations for\n"
1428 " int semume; /* Maximum number of undo entries per\n"
1429 " process; unused within kernel */\n"
1430 " int semusz; /* Size of struct sem_undo */\n"
1431 " int semvmx; /* Maximum semaphore value */\n"
1432 " int semaem; /* Max. value that can be recorded for\n"
1433 " semaphore adjustment (SEM_UNDO) */\n"
1438 #: build/C/man2/semctl.2:217
1440 "The I<semmsl>, I<semmns>, I<semopm>, and I<semmni> settings can be changed "
1441 "via I</proc/sys/kernel/sem>; see B<proc>(5) for details."
1445 #: build/C/man2/semctl.2:217
1447 msgid "B<SEM_INFO> (Linux-specific)"
1451 #: build/C/man2/semctl.2:231
1453 "Returns a I<seminfo> structure containing the same information as for "
1454 "B<IPC_INFO>, except that the following fields are returned with information "
1455 "about system resources consumed by semaphores: the I<semusz> field returns "
1456 "the number of semaphore sets that currently exist on the system; and the "
1457 "I<semaem> field returns the total number of semaphores in all semaphore sets "
1462 #: build/C/man2/semctl.2:231
1464 msgid "B<SEM_STAT> (Linux-specific)"
1468 #: build/C/man2/semctl.2:242
1470 "Returns a I<semid_ds> structure as for B<IPC_STAT>. However, the I<semid> "
1471 "argument is not a semaphore identifier, but instead an index into the "
1472 "kernel's internal array that maintains information about all semaphore sets "
1477 #: build/C/man2/semctl.2:242
1483 #: build/C/man2/semctl.2:253
1485 "Return B<semval> (i.e., the current value) for all semaphores of the set "
1486 "into I<arg.array>. The argument I<semnum> is ignored. The calling process "
1487 "must have read permission on the semaphore set."
1491 #: build/C/man2/semctl.2:253 build/C/man2/semctl.2:351
1497 #: build/C/man2/semctl.2:266
1499 "The system call returns the value of B<semncnt> for the I<semnum>-th "
1500 "semaphore of the set (i.e., the number of processes waiting for an increase "
1501 "of B<semval> for the I<semnum>-th semaphore of the set). The calling "
1502 "process must have read permission on the semaphore set."
1506 #: build/C/man2/semctl.2:266 build/C/man2/semctl.2:355
1512 #: build/C/man2/semctl.2:279
1514 "The system call returns the value of B<sempid> for the I<semnum>-th "
1515 "semaphore of the set (i.e., the PID of the process that executed the last "
1516 "B<semop>(2) call for the I<semnum>-th semaphore of the set). The calling "
1517 "process must have read permission on the semaphore set."
1521 #: build/C/man2/semctl.2:279 build/C/man2/semctl.2:359
1527 #: build/C/man2/semctl.2:287
1529 "The system call returns the value of B<semval> for the I<semnum>-th "
1530 "semaphore of the set. The calling process must have read permission on the "
1535 #: build/C/man2/semctl.2:287 build/C/man2/semctl.2:363
1541 #: build/C/man2/semctl.2:300
1543 "The system call returns the value of B<semzcnt> for the I<semnum>-th "
1544 "semaphore of the set (i.e., the number of processes waiting for B<semval> of "
1545 "the I<semnum>-th semaphore of the set to become 0). The calling process "
1546 "must have read permission on the semaphore set."
1550 #: build/C/man2/semctl.2:300
1556 #: build/C/man2/semctl.2:322
1558 "Set B<semval> for all semaphores of the set using I<arg.array>, updating "
1559 "also the I<sem_ctime> member of the I<semid_ds> structure associated with "
1560 "the set. Undo entries (see B<semop>(2)) are cleared for altered semaphores "
1561 "in all processes. If the changes to semaphore values would permit blocked "
1562 "B<semop>(2) calls in other processes to proceed, then those processes are "
1563 "woken up. The argument I<semnum> is ignored. The calling process must have "
1564 "alter (write) permission on the semaphore set."
1568 #: build/C/man2/semctl.2:322
1574 #: build/C/man2/semctl.2:340
1576 "Set the value of B<semval> to I<arg.val> for the I<semnum>-th semaphore of "
1577 "the set, updating also the I<sem_ctime> member of the I<semid_ds> structure "
1578 "associated with the set. Undo entries are cleared for altered semaphores in "
1579 "all processes. If the changes to semaphore values would permit blocked "
1580 "B<semop>(2) calls in other processes to proceed, then those processes are "
1581 "woken up. The calling process must have alter permission on the semaphore "
1586 #: build/C/man2/semctl.2:347
1587 msgid "On failure B<semctl>() returns -1 with I<errno> indicating the error."
1591 #: build/C/man2/semctl.2:351
1593 "Otherwise the system call returns a nonnegative value depending on I<cmd> as "
1598 #: build/C/man2/semctl.2:355
1599 msgid "the value of B<semncnt>."
1603 #: build/C/man2/semctl.2:359
1604 msgid "the value of B<sempid>."
1608 #: build/C/man2/semctl.2:363
1609 msgid "the value of B<semval>."
1613 #: build/C/man2/semctl.2:367
1614 msgid "the value of B<semzcnt>."
1618 #: build/C/man2/semctl.2:367
1624 #: build/C/man2/semctl.2:375
1626 "the index of the highest used entry in the kernel's internal array recording "
1627 "information about all semaphore sets. (This information can be used with "
1628 "repeated B<SEM_STAT> operations to obtain information about all semaphore "
1629 "sets on the system.)"
1633 #: build/C/man2/semctl.2:375
1639 #: build/C/man2/semctl.2:379
1640 msgid "As for B<IPC_INFO>."
1644 #: build/C/man2/semctl.2:379
1650 #: build/C/man2/semctl.2:383
1651 msgid "the identifier of the semaphore set whose index was given in I<semid>."
1655 #: build/C/man2/semctl.2:387
1656 msgid "All other I<cmd> values return 0 on success."
1660 #: build/C/man2/semctl.2:391
1661 msgid "On failure, I<errno> will be set to one of the following:"
1665 #: build/C/man2/semctl.2:410
1667 "The argument I<cmd> has one of the values B<GETALL>, B<GETPID>, B<GETVAL>, "
1668 "B<GETNCNT>, B<GETZCNT>, B<IPC_STAT>, B<SEM_STAT>, B<SETALL>, or B<SETVAL> "
1669 "and the calling process does not have the required permissions on the "
1670 "semaphore set and does not have the B<CAP_IPC_OWNER> capability."
1674 #: build/C/man2/semctl.2:410 build/C/man2/semop.2:347
1680 #: build/C/man2/semctl.2:417
1681 msgid "The address pointed to by I<arg.buf> or I<arg.array> isn't accessible."
1685 #: build/C/man2/semctl.2:417 build/C/man2/semop.2:360
1691 #: build/C/man2/semctl.2:420 build/C/man2/semop.2:363
1692 msgid "The semaphore set was removed."
1696 #: build/C/man2/semctl.2:431
1698 "Invalid value for I<cmd> or I<semid>. Or: for a B<SEM_STAT> operation, the "
1699 "index value specified in I<semid> referred to an array slot that is "
1704 #: build/C/man2/semctl.2:431
1710 #: build/C/man2/semctl.2:449
1712 "The argument I<cmd> has the value B<IPC_SET> or B<IPC_RMID> but the "
1713 "effective user ID of the calling process is not the creator (as found in "
1714 "I<sem_perm.cuid>) or the owner (as found in I<sem_perm.uid>) of the "
1715 "semaphore set, and the process does not have the B<CAP_SYS_ADMIN> "
1720 #: build/C/man2/semctl.2:449 build/C/man2/semop.2:382
1726 #: build/C/man2/semctl.2:462
1728 "The argument I<cmd> has the value B<SETALL> or B<SETVAL> and the value to "
1729 "which B<semval> is to be set (for some semaphore of the set) is less than 0 "
1730 "or greater than the implementation limit B<SEMVMX>."
1733 #. SVr4 documents additional error conditions EINVAL, EFBIG, ENOSPC.
1735 #: build/C/man2/semctl.2:465 build/C/man2/semget.2:223 build/C/man2/semop.2:400
1736 msgid "SVr4, POSIX.1-2001."
1740 #: build/C/man2/semctl.2:476
1742 "POSIX.1-2001 specifies the I<sem_nsems> field of the I<semid_ds> structure "
1743 "as having the type I<unsigned\\ short>, and the field is so defined on most "
1744 "other systems. It was also so defined on Linux 2.2 and earlier, but, since "
1745 "Linux 2.4, the field has the type I<unsigned\\ long>."
1748 #. Like Linux, the FreeBSD man pages still document
1749 #. the inclusion of these header files.
1751 #: build/C/man2/semctl.2:489 build/C/man2/semget.2:236 build/C/man2/semop.2:413
1753 "The inclusion of I<E<lt>sys/types.hE<gt>> and I<E<lt>sys/ipc.hE<gt>> isn't "
1754 "required on Linux or by any version of POSIX. However, some old "
1755 "implementations required the inclusion of these header files, and the SVID "
1756 "also documented their inclusion. Applications intended to be portable to "
1757 "such old systems may need to include these header files."
1761 #: build/C/man2/semctl.2:501
1763 "The B<IPC_INFO>, B<SEM_STAT> and B<SEM_INFO> operations are used by the "
1764 "B<ipcs>(1) program to provide information on allocated resources. In the "
1765 "future these may modified or moved to a I</proc> filesystem interface."
1769 #: build/C/man2/semctl.2:514
1771 "Various fields in a I<struct semid_ds> were typed as I<short> under Linux "
1772 "2.2 and have become I<long> under Linux 2.4. To take advantage of this, a "
1773 "recompilation under glibc-2.1.91 or later should suffice. (The kernel "
1774 "distinguishes old and new calls by an B<IPC_64> flag in I<cmd>.)"
1778 #: build/C/man2/semctl.2:523
1780 "In some earlier versions of glibc, the I<semun> union was defined in "
1781 "I<E<lt>sys/sem.hE<gt>>, but POSIX.1-2001 requires that the caller define "
1782 "this union. On versions of glibc where this union is I<not> defined, the "
1783 "macro B<_SEM_SEMUN_UNDEFINED> is defined in I<E<lt>sys/sem.hE<gt>>."
1787 #: build/C/man2/semctl.2:527
1788 msgid "The following system limit on semaphore sets affects a B<semctl>() call:"
1792 #: build/C/man2/semctl.2:527 build/C/man2/semop.2:469
1798 #: build/C/man2/semctl.2:532
1799 msgid "Maximum value for B<semval>: implementation dependent (32767)."
1803 #: build/C/man2/semctl.2:536
1805 "For greater portability it is best to always call B<semctl>() with four "
1810 #: build/C/man2/semctl.2:543
1812 "B<ipc>(2), B<semget>(2), B<semop>(2), B<capabilities>(7), "
1813 "B<sem_overview>(7), B<svipc>(7)"
1817 #: build/C/man2/semget.2:36
1823 #: build/C/man2/semget.2:36
1829 #: build/C/man2/semget.2:39
1830 msgid "semget - get a System V semaphore set identifier"
1834 #: build/C/man2/semget.2:49
1835 msgid "B<int semget(key_t >I<key>B<,> B<int >I<nsems>B<,> B<int >I<semflg>B<);>"
1839 #: build/C/man2/semget.2:67
1841 "The B<semget>() system call returns the System V semaphore set identifier "
1842 "associated with the argument I<key>. A new set of I<nsems> semaphores is "
1843 "created if I<key> has the value B<IPC_PRIVATE> or if no existing semaphore "
1844 "set is associated with I<key> and B<IPC_CREAT> is specified in I<semflg>."
1848 #: build/C/man2/semget.2:86
1850 "If I<semflg> specifies both B<IPC_CREAT> and B<IPC_EXCL> and a semaphore set "
1851 "already exists for I<key>, then B<semget>() fails with I<errno> set to "
1852 "B<EEXIST>. (This is analogous to the effect of the combination B<O_CREAT | "
1853 "O_EXCL> for B<open>(2).)"
1857 #: build/C/man2/semget.2:99
1859 "Upon creation, the least significant 9 bits of the argument I<semflg> define "
1860 "the permissions (for owner, group and others) for the semaphore set. These "
1861 "bits have the same format, and the same meaning, as the I<mode> argument of "
1862 "B<open>(2) (though the execute permissions are not meaningful for "
1863 "semaphores, and write permissions mean permission to alter semaphore "
1867 #. In truth, every one of the many implementations that I've tested sets
1868 #. the values to zero, but I suppose there is/was some obscure
1869 #. implementation out there that does not.
1871 #: build/C/man2/semget.2:109
1873 "The values of the semaphores in a newly created set are indeterminate. "
1874 "(POSIX.1-2001 is explicit on this point.) Although Linux, like many other "
1875 "implementations, initializes the semaphore values to 0, a portable "
1876 "application cannot rely on this: it should explicitly initialize the "
1877 "semaphores to the desired values."
1881 #: build/C/man2/semget.2:117
1883 "When creating a new semaphore set, B<semget>() initializes the set's "
1884 "associated data structure, I<semid_ds> (see B<semctl>(2)), as follows:"
1888 #: build/C/man2/semget.2:122
1890 "I<sem_perm.cuid> and I<sem_perm.uid> are set to the effective user ID of the "
1895 #: build/C/man2/semget.2:127
1897 "I<sem_perm.cgid> and I<sem_perm.gid> are set to the effective group ID of "
1898 "the calling process."
1902 #: build/C/man2/semget.2:132
1904 "The least significant 9 bits of I<sem_perm.mode> are set to the least "
1905 "significant 9 bits of I<semflg>."
1909 #: build/C/man2/semget.2:136
1910 msgid "I<sem_nsems> is set to the value of I<nsems>."
1914 #: build/C/man2/semget.2:139
1915 msgid "I<sem_otime> is set to 0."
1919 #: build/C/man2/semget.2:142
1920 msgid "I<sem_ctime> is set to the current time."
1924 #: build/C/man2/semget.2:153
1926 "The argument I<nsems> can be 0 (a don't care) when a semaphore set is not "
1927 "being created. Otherwise I<nsems> must be greater than 0 and less than or "
1928 "equal to the maximum number of semaphores per semaphore set (B<SEMMSL>)."
1931 #. and a check is made to see if it is marked for destruction.
1933 #: build/C/man2/semget.2:157
1934 msgid "If the semaphore set already exists, the permissions are verified."
1938 #: build/C/man2/semget.2:163
1940 "If successful, the return value will be the semaphore set identifier (a "
1941 "nonnegative integer), otherwise -1 is returned, with I<errno> indicating the "
1946 #: build/C/man2/semget.2:167
1947 msgid "On failure I<errno> will be set to one of the following:"
1951 #: build/C/man2/semget.2:175
1953 "A semaphore set exists for I<key>, but the calling process does not have "
1954 "permission to access the set, and does not have the B<CAP_IPC_OWNER> "
1960 #. The semaphore set is marked to be deleted.
1962 #: build/C/man2/semget.2:188
1964 "A semaphore set exists for I<key> and I<semflg> specified both B<IPC_CREAT> "
1969 #: build/C/man2/semget.2:199
1971 "I<nsems> is less than 0 or greater than the limit on the number of "
1972 "semaphores per semaphore set (B<SEMMSL>), or a semaphore set corresponding "
1973 "to I<key> already exists, and I<nsems> is larger than the number of "
1974 "semaphores in that set."
1978 #: build/C/man2/semget.2:207
1980 "No semaphore set exists for I<key> and I<semflg> did not specify "
1985 #: build/C/man2/semget.2:211
1987 "A semaphore set has to be created but the system does not have enough memory "
1988 "for the new data structure."
1992 #: build/C/man2/semget.2:211
1998 #: build/C/man2/semget.2:219
2000 "A semaphore set has to be created but the system limit for the maximum "
2001 "number of semaphore sets (B<SEMMNI>), or the system wide maximum number of "
2002 "semaphores (B<SEMMNS>), would be exceeded."
2006 #: build/C/man2/semget.2:246
2008 "B<IPC_PRIVATE> isn't a flag field but a I<key_t> type. If this special "
2009 "value is used for I<key>, the system call ignores everything but the least "
2010 "significant 9 bits of I<semflg> and creates a new semaphore set (on "
2015 #: build/C/man2/semget.2:250
2017 "The following limits on semaphore set resources affect the B<semget>() "
2022 #: build/C/man2/semget.2:250
2027 #. This /proc file is not available in Linux 2.2 and earlier -- MTK
2029 #: build/C/man2/semget.2:256
2031 "System wide maximum number of semaphore sets: policy dependent (on Linux, "
2032 "this limit can be read and modified via the fourth field of "
2033 "I</proc/sys/kernel/sem>)."
2037 #: build/C/man2/semget.2:256
2043 #: build/C/man2/semget.2:261
2045 "Maximum number of semaphores per semid: implementation dependent (on Linux, "
2046 "this limit can be read and modified via the first field of "
2047 "I</proc/sys/kernel/sem>)."
2051 #: build/C/man2/semget.2:261
2057 #: build/C/man2/semget.2:269
2059 "System wide maximum number of semaphores: policy dependent (on Linux, this "
2060 "limit can be read and modified via the second field of "
2061 "I</proc/sys/kernel/sem>). Values greater than B<SEMMSL * SEMMNI> makes it "
2066 #: build/C/man2/semget.2:269 build/C/man2/semop.2:481
2072 #: build/C/man2/semget.2:275
2074 "The name choice B<IPC_PRIVATE> was perhaps unfortunate, B<IPC_NEW> would "
2075 "more clearly show its function."
2078 #. In fact they are initialized to zero on Linux, but POSIX.1-2001
2079 #. does not specify this, and we can't portably rely on it.
2081 #: build/C/man2/semget.2:294
2083 "The semaphores in a set are not initialized by B<semget>(). In order to "
2084 "initialize the semaphores, B<semctl>(2) must be used to perform a B<SETVAL> "
2085 "or a B<SETALL> operation on the semaphore set. (Where multiple peers do not "
2086 "know who will be the first to initialize the set, checking for a nonzero "
2087 "I<sem_otime> in the associated data structure retrieved by a B<semctl>(2) "
2088 "B<IPC_STAT> operation can be used to avoid races.)"
2092 #: build/C/man2/semget.2:301
2094 "B<semctl>(2), B<semop>(2), B<ftok>(3), B<capabilities>(7), "
2095 "B<sem_overview>(7), B<svipc>(7)"
2099 #: build/C/man2/semop.2:35
2105 #: build/C/man2/semop.2:35
2111 #: build/C/man2/semop.2:38
2112 msgid "semop, semtimedop - System V semaphore operations"
2116 #: build/C/man2/semop.2:45
2119 "B<int semop(int >I<semid>B<, struct sembuf *>I<sops>B<, unsigned "
2124 #: build/C/man2/semop.2:48
2127 "B<int semtimedop(int >I<semid>B<, struct sembuf *>I<sops>B<, unsigned "
2129 "B< struct timespec *>I<timeout>B<);>\n"
2133 #: build/C/man2/semop.2:57
2134 msgid "B<semtimedop>(): _GNU_SOURCE"
2138 #: build/C/man2/semop.2:60
2140 "Each semaphore in a System V semaphore set has the following associated "
2145 #: build/C/man2/semop.2:67
2148 "unsigned short semval; /* semaphore value */\n"
2149 "unsigned short semzcnt; /* # waiting for zero */\n"
2150 "unsigned short semncnt; /* # waiting for increase */\n"
2151 "pid_t sempid; /* ID of process that did last op */\n"
2155 #: build/C/man2/semop.2:81
2157 "B<semop>() performs operations on selected semaphores in the set indicated "
2158 "by I<semid>. Each of the I<nsops> elements in the array pointed to by "
2159 "I<sops> specifies an operation to be performed on a single semaphore. The "
2160 "elements of this structure are of type I<struct sembuf>, containing the "
2161 "following members:"
2165 #: build/C/man2/semop.2:87
2168 "unsigned short sem_num; /* semaphore number */\n"
2169 "short sem_op; /* semaphore operation */\n"
2170 "short sem_flg; /* operation flags */\n"
2174 #: build/C/man2/semop.2:99
2176 "Flags recognized in I<sem_flg> are B<IPC_NOWAIT> and B<SEM_UNDO>. If an "
2177 "operation specifies B<SEM_UNDO>, it will be automatically undone when the "
2178 "process terminates."
2182 #: build/C/man2/semop.2:114
2184 "The set of operations contained in I<sops> is performed in I<array order>, "
2185 "and I<atomically>, that is, the operations are performed either as a "
2186 "complete unit, or not at all. The behavior of the system call if not all "
2187 "operations can be performed immediately depends on the presence of the "
2188 "B<IPC_NOWAIT> flag in the individual I<sem_flg> fields, as noted below."
2192 #: build/C/man2/semop.2:121
2194 "Each operation is performed on the I<sem_num>-th semaphore of the semaphore "
2195 "set, where the first semaphore of the set is numbered 0. There are three "
2196 "types of operation, distinguished by the value of I<sem_op>."
2200 #: build/C/man2/semop.2:136
2202 "If I<sem_op> is a positive integer, the operation adds this value to the "
2203 "semaphore value (I<semval>). Furthermore, if B<SEM_UNDO> is specified for "
2204 "this operation, the system subtracts the value I<sem_op> from the semaphore "
2205 "adjustment (I<semadj>) value for this semaphore. This operation can always "
2206 "proceed\\(emit never forces a thread to wait. The calling process must have "
2207 "alter permission on the semaphore set."
2211 #: build/C/man2/semop.2:161
2213 "If I<sem_op> is zero, the process must have read permission on the semaphore "
2214 "set. This is a \"wait-for-zero\" operation: if I<semval> is zero, the "
2215 "operation can immediately proceed. Otherwise, if B<IPC_NOWAIT> is specified "
2216 "in I<sem_flg>, B<semop>() fails with I<errno> set to B<EAGAIN> (and none of "
2217 "the operations in I<sops> is performed). Otherwise I<semzcnt> (the count of "
2218 "threads waiting until this semaphore's value becomes zero) is incremented "
2219 "by one and the thread sleeps until one of the following occurs:"
2223 #: build/C/man2/semop.2:161 build/C/man2/semop.2:166 build/C/man2/semop.2:174 build/C/man2/semop.2:184 build/C/man2/semop.2:237 build/C/man2/semop.2:242 build/C/man2/semop.2:249 build/C/man2/semop.2:259
2229 #: build/C/man2/semop.2:166
2230 msgid "I<semval> becomes 0, at which time the value of I<semzcnt> is decremented."
2234 #: build/C/man2/semop.2:174
2236 "The semaphore set is removed: B<semop>() fails, with I<errno> set to "
2241 #: build/C/man2/semop.2:184
2243 "The calling thread catches a signal: the value of I<semzcnt> is decremented "
2244 "and B<semop>() fails, with I<errno> set to B<EINTR>."
2248 #: build/C/man2/semop.2:195
2250 "The time limit specified by I<timeout> in a B<semtimedop>() call expires: "
2251 "B<semop>() fails, with I<errno> set to B<EAGAIN>."
2255 #: build/C/man2/semop.2:237
2257 "If I<sem_op> is less than zero, the process must have alter permission on "
2258 "the semaphore set. If I<semval> is greater than or equal to the absolute "
2259 "value of I<sem_op>, the operation can proceed immediately: the absolute "
2260 "value of I<sem_op> is subtracted from I<semval>, and, if B<SEM_UNDO> is "
2261 "specified for this operation, the system adds the absolute value of "
2262 "I<sem_op> to the semaphore adjustment (I<semadj>) value for this "
2263 "semaphore. If the absolute value of I<sem_op> is greater than I<semval>, "
2264 "and B<IPC_NOWAIT> is specified in I<sem_flg>, B<semop>() fails, with "
2265 "I<errno> set to B<EAGAIN> (and none of the operations in I<sops> is "
2266 "performed). Otherwise I<semncnt> (the counter of threads waiting for this "
2267 "semaphore's value to increase) is incremented by one and the thread sleeps "
2268 "until one of the following occurs:"
2272 #: build/C/man2/semop.2:242
2274 "I<semval> becomes greater than or equal to the absolute value of I<sem_op>: "
2275 "the operation now proceeds, as described above."
2279 #: build/C/man2/semop.2:249
2281 "The semaphore set is removed from the system: B<semop>() fails, with "
2282 "I<errno> set to B<EIDRM>."
2286 #: build/C/man2/semop.2:259
2288 "The calling thread catches a signal: the value of I<semncnt> is decremented "
2289 "and B<semop>() fails, with I<errno> set to B<EINTR>."
2293 #: build/C/man2/semop.2:268
2295 "The time limit specified by I<timeout> in a B<semtimedop>() call expires: "
2296 "the system call fails, with I<errno> set to B<EAGAIN>."
2302 #: build/C/man2/semop.2:279
2304 "On successful completion, the I<sempid> value for each semaphore specified "
2305 "in the array pointed to by I<sops> is set to the caller's process ID. In "
2306 "addition, the I<sem_otime> is set to the current time."
2310 #: build/C/man2/semop.2:309
2312 "B<semtimedop>() behaves identically to B<semop>() except that in those "
2313 "cases where the calling thread would sleep, the duration of that sleep is "
2314 "limited by the amount of elapsed time specified by the I<timespec> structure "
2315 "whose address is passed in the I<timeout> argument. (This sleep interval "
2316 "will be rounded up to the system clock granularity, and kernel scheduling "
2317 "delays mean that the interval may overrun by a small amount.) If the "
2318 "specified time limit has been reached, B<semtimedop>() fails with I<errno> "
2319 "set to B<EAGAIN> (and none of the operations in I<sops> is performed). If "
2320 "the I<timeout> argument is NULL, then B<semtimedop>() behaves exactly like "
2325 #: build/C/man2/semop.2:319
2327 "If successful B<semop>() and B<semtimedop>() return 0; otherwise they "
2328 "return -1 with I<errno> indicating the error."
2332 #: build/C/man2/semop.2:323
2333 msgid "On failure, I<errno> is set to one of the following:"
2337 #: build/C/man2/semop.2:323
2343 #: build/C/man2/semop.2:331
2345 "The argument I<nsops> is greater than B<SEMOPM>, the maximum number of "
2346 "operations allowed per system call."
2350 #: build/C/man2/semop.2:338
2352 "The calling process does not have the permissions required to perform the "
2353 "specified semaphore operations, and does not have the B<CAP_IPC_OWNER> "
2358 #: build/C/man2/semop.2:347
2360 "An operation could not proceed immediately and either B<IPC_NOWAIT> was "
2361 "specified in I<sem_flg> or the time limit specified in I<timeout> expired."
2365 #: build/C/man2/semop.2:354
2367 "An address specified in either the I<sops> or the I<timeout> argument isn't "
2372 #: build/C/man2/semop.2:354
2378 #: build/C/man2/semop.2:360
2380 "For some operation the value of I<sem_num> is less than 0 or greater than or "
2381 "equal to the number of semaphores in the set."
2385 #: build/C/man2/semop.2:367
2387 "While blocked in this system call, the thread caught a signal; see "
2392 #: build/C/man2/semop.2:374
2394 "The semaphore set doesn't exist, or I<semid> is less than zero, or I<nsops> "
2395 "has a nonpositive value."
2399 #: build/C/man2/semop.2:382
2401 "The I<sem_flg> of some operation specified B<SEM_UNDO> and the system does "
2402 "not have enough memory to allocate the undo structure."
2406 #: build/C/man2/semop.2:390
2408 "For some operation I<sem_op+semval> is greater than B<SEMVMX>, the "
2409 "implementation dependent maximum value for I<semval>."
2413 #: build/C/man2/semop.2:390
2419 #: build/C/man2/semop.2:397
2421 "B<semtimedop>() first appeared in Linux 2.5.52, and was subsequently "
2422 "backported into kernel 2.4.22. Glibc support for B<semtimedop>() first "
2423 "appeared in version 2.3.3."
2427 #: build/C/man2/semop.2:421
2429 "The I<sem_undo> structures of a process aren't inherited by the child "
2430 "produced by B<fork>(2), but they are inherited across an B<execve>(2) "
2435 #: build/C/man2/semop.2:427
2437 "B<semop>() is never automatically restarted after being interrupted by a "
2438 "signal handler, regardless of the setting of the B<SA_RESTART> flag when "
2439 "establishing a signal handler."
2443 #: build/C/man2/semop.2:452
2445 "A semaphore adjustment (I<semadj>) value is a per-process, per-semaphore "
2446 "integer that is the negated sum of all operations performed on a semaphore "
2447 "specifying the B<SEM_UNDO> flag. Each process has a list of I<semadj> "
2448 "values\\(emone value for each semaphore on which it has operated using "
2449 "B<SEM_UNDO>. When a process terminates, each of its per-semaphore I<semadj> "
2450 "values is added to the corresponding semaphore, thus undoing the effect of "
2451 "that process's operations on the semaphore (but see BUGS below). When a "
2452 "semaphore's value is directly set using the B<SETVAL> or B<SETALL> request "
2453 "to B<semctl>(2), the corresponding I<semadj> values in all processes are "
2458 #: build/C/man2/semop.2:457
2460 "The I<semval>, I<sempid>, I<semzcnt>, and I<semnct> values for a semaphore "
2461 "can all be retrieved using appropriate B<semctl>(2) calls."
2465 #: build/C/man2/semop.2:461
2466 msgid "The following limits on semaphore set resources affect the B<semop>() call:"
2470 #: build/C/man2/semop.2:461
2475 #. This /proc file is not available in Linux 2.2 and earlier -- MTK
2477 #: build/C/man2/semop.2:469
2479 "Maximum number of operations allowed for one B<semop>() call (32) (on "
2480 "Linux, this limit can be read and modified via the third field of "
2481 "I</proc/sys/kernel/sem>)."
2485 #: build/C/man2/semop.2:474
2486 msgid "Maximum allowable value for I<semval>: implementation dependent (32767)."
2490 #: build/C/man2/semop.2:481
2492 "The implementation has no intrinsic limits for the adjust on exit maximum "
2493 "value (B<SEMAEM>), the system wide maximum number of undo structures "
2494 "(B<SEMMNU>) and the per-process maximum number of undo entries system "
2499 #: build/C/man2/semop.2:502
2501 "When a process terminates, its set of associated I<semadj> structures is "
2502 "used to undo the effect of all of the semaphore operations it performed with "
2503 "the B<SEM_UNDO> flag. This raises a difficulty: if one (or more) of these "
2504 "semaphore adjustments would result in an attempt to decrease a semaphore's "
2505 "value below zero, what should an implementation do? One possible approach "
2506 "would be to block until all the semaphore adjustments could be performed. "
2507 "This is however undesirable since it could force process termination to "
2508 "block for arbitrarily long periods. Another possibility is that such "
2509 "semaphore adjustments could be ignored altogether (somewhat analogously to "
2510 "failing when B<IPC_NOWAIT> is specified for a semaphore operation). Linux "
2511 "adopts a third approach: decreasing the semaphore value as far as possible "
2512 "(i.e., to zero) and allowing process termination to proceed immediately."
2516 #. http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
2518 #. http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
2520 #: build/C/man2/semop.2:511
2522 "In kernels 2.6.x, x E<lt>= 10, there is a bug that in some circumstances "
2523 "prevents a thread that is waiting for a semaphore value to become zero from "
2524 "being woken up when the value does actually become zero. This bug is fixed "
2529 #: build/C/man2/semop.2:516
2531 "The following code segment uses B<semop>() to atomically wait for the value "
2532 "of semaphore 0 to become zero, and then increment the semaphore value by "
2537 #: build/C/man2/semop.2:520
2540 " struct sembuf sops[2];\n"
2545 #: build/C/man2/semop.2:522
2547 msgid " /* Code to set I<semid> omitted */\n"
2551 #: build/C/man2/semop.2:526
2554 " sops[0].sem_num = 0; /* Operate on semaphore 0 */\n"
2555 " sops[0].sem_op = 0; /* Wait for value to equal 0 */\n"
2556 " sops[0].sem_flg = 0;\n"
2560 #: build/C/man2/semop.2:530
2563 " sops[1].sem_num = 0; /* Operate on semaphore 0 */\n"
2564 " sops[1].sem_op = 1; /* Increment value by one */\n"
2565 " sops[1].sem_flg = 0;\n"
2569 #: build/C/man2/semop.2:535
2572 " if (semop(semid, sops, 2) == -1) {\n"
2573 " perror(\"semop\");\n"
2574 " exit(EXIT_FAILURE);\n"
2579 #: build/C/man2/semop.2:545
2581 "B<clone>(2), B<semctl>(2), B<semget>(2), B<sigaction>(2), "
2582 "B<capabilities>(7), B<sem_overview>(7), B<svipc>(7), B<time>(7)"