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: 2012-03-19 23:50+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_unlink.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:39 build/C/man2/semget.2:34 build/C/man2/semop.2:33
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:39 build/C/man2/semget.2:34 build/C/man2/semop.2:33
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:40 build/C/man2/semget.2:35 build/C/man2/semop.2:34
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:42 build/C/man2/semget.2:37 build/C/man2/semop.2:36
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<-lrt> or 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:50 build/C/man2/semget.2:47 build/C/man2/semop.2:55
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:338 build/C/man2/semget.2:155 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:385 build/C/man2/semget.2:161 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:418 build/C/man2/semget.2:186 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:460 build/C/man2/semget.2:217 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:463 build/C/man2/semget.2:221 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:263 build/C/man2/semctl.2:509 build/C/man2/semget.2:279 build/C/man2/semop.2:513
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:269 build/C/man2/semctl.2:516 build/C/man2/semget.2:286 build/C/man2/semop.2:521
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:276 build/C/man2/semctl.2:523 build/C/man2/semget.2:293 build/C/man2/semop.2:528
167 "This page is part of release 3.35 of the Linux I<man-pages> project. A "
168 "description of the project, and information about reporting bugs, can be "
169 "found at http://man7.org/linux/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:26
304 #: build/C/man3/sem_init.3:29
305 msgid "sem_init - initialize an unnamed semaphore"
309 #: build/C/man3/sem_init.3:34
312 "B<int sem_init(sem_t *>I<sem>B<, int >I<pshared>B<, unsigned int "
317 #: build/C/man3/sem_init.3:44
319 "B<sem_init>() initializes the unnamed semaphore at the address pointed to "
320 "by I<sem>. The I<value> argument specifies the initial value for the "
325 #: build/C/man3/sem_init.3:49
327 "The I<pshared> argument indicates whether this semaphore is to be shared "
328 "between the threads of a process, or between processes."
332 #: build/C/man3/sem_init.3:57
334 "If I<pshared> has the value 0, then the semaphore is shared between the "
335 "threads of a process, and should be located at some address that is visible "
336 "to all threads (e.g., a global variable, or a variable allocated dynamically "
341 #: build/C/man3/sem_init.3:74
343 "If I<pshared> is nonzero, then the semaphore is shared between processes, "
344 "and should be located in a region of shared memory (see B<shm_open>(3), "
345 "B<mmap>(2), and B<shmget>(2)). (Since a child created by B<fork>(2) "
346 "inherits its parent's memory mappings, it can also access the semaphore.) "
347 "Any process that can access the shared memory region can operate on the "
348 "semaphore using B<sem_post>(3), B<sem_wait>(3), etc."
352 #: build/C/man3/sem_init.3:77
354 "Initializing a semaphore that has already been initialized results in "
355 "undefined behavior."
359 #: build/C/man3/sem_init.3:83
361 "B<sem_init>() returns 0 on success; on error, -1 is returned, and I<errno> "
362 "is set to indicate the error."
366 #: build/C/man3/sem_init.3:89
367 msgid "I<value> exceeds B<SEM_VALUE_MAX>."
371 #: build/C/man3/sem_init.3:89
377 #: build/C/man3/sem_init.3:95
379 "I<pshared> is nonzero, but the system does not support process-shared "
380 "semaphores (see B<sem_overview>(7))."
384 #: build/C/man3/sem_init.3:102
386 "Bizarrely, POSIX.1-2001 does not specify the value that should be returned "
387 "by a successful call to B<sem_init>(). POSIX.1-2008 rectifies this, "
388 "specifying the zero return on success."
392 #: build/C/man3/sem_init.3:107
393 msgid "B<sem_destroy>(3), B<sem_post>(3), B<sem_wait>(3), B<sem_overview>(7)"
397 #: build/C/man3/sem_open.3:26
403 #: build/C/man3/sem_open.3:26
409 #: build/C/man3/sem_open.3:29
410 msgid "sem_open - initialize and open a named semaphore"
414 #: build/C/man3/sem_open.3:34
417 "B<#include E<lt>fcntl.hE<gt>> /* For O_* constants */\n"
418 "B<#include E<lt>sys/stat.hE<gt>> /* For mode constants */\n"
419 "B<#include E<lt>semaphore.hE<gt>>\n"
423 #: build/C/man3/sem_open.3:38
426 "B<sem_t *sem_open(const char *>I<name>B<, int >I<oflag>B<);>\n"
427 "B<sem_t *sem_open(const char *>I<name>B<, int >I<oflag>B<, >\n"
428 "B< mode_t >I<mode>B<, unsigned int >I<value>B<);>\n"
432 #: build/C/man3/sem_open.3:50
434 "B<sem_open>() creates a new POSIX semaphore or opens an existing "
435 "semaphore. The semaphore is identified by I<name>. For details of the "
436 "construction of I<name>, see B<sem_overview>(7)."
439 #. In reality the file system IDs are used on Linux.
441 #: build/C/man3/sem_open.3:76
443 "The I<oflag> argument specifies flags that control the operation of the "
444 "call. (Definitions of the flags values can be obtained by including "
445 "I<E<lt>fcntl.hE<gt>>.) If B<O_CREAT> is specified in I<oflag>, then the "
446 "semaphore is created if it does not already exist. The owner (user ID) of "
447 "the semaphore is set to the effective user ID of the calling process. The "
448 "group ownership (group ID) is set to the effective group ID of the calling "
449 "process. If both B<O_CREAT> and B<O_EXCL> are specified in I<oflag>, then "
450 "an error is returned if a semaphore with the given I<name> already exists."
454 #: build/C/man3/sem_open.3:104
456 "If B<O_CREAT> is specified in I<oflag>, then two additional arguments must "
457 "be supplied. The I<mode> argument specifies the permissions to be placed on "
458 "the new semaphore, as for B<open>(2). (Symbolic definitions for the "
459 "permissions bits can be obtained by including I<E<lt>sys/stat.hE<gt>>.) The "
460 "permissions settings are masked against the process umask. Both read and "
461 "write permission should be granted to each class of user that will access "
462 "the semaphore. The I<value> argument specifies the initial value for the "
463 "new semaphore. If B<O_CREAT> is specified, and a semaphore with the given "
464 "I<name> already exists, then I<mode> and I<value> are ignored."
468 #: build/C/man3/sem_open.3:116
470 "On success, B<sem_open>() returns the address of the new semaphore; this "
471 "address is used when calling other semaphore-related functions. On error, "
472 "B<sem_open>() returns B<SEM_FAILED>, with I<errno> set to indicate the "
477 #: build/C/man3/sem_open.3:117 build/C/man3/sem_unlink.3:51 build/C/man2/semctl.2:389 build/C/man2/semget.2:165 build/C/man2/semop.2:331
483 #: build/C/man3/sem_open.3:121
484 msgid "The semaphore exists, but the caller does not have permission to open it."
488 #: build/C/man3/sem_open.3:121 build/C/man2/semget.2:173
494 #: build/C/man3/sem_open.3:132
496 "Both B<O_CREAT> and B<O_EXCL> were specified in I<oflag>, but a semaphore "
497 "with this I<name> already exists."
501 #: build/C/man3/sem_open.3:137
502 msgid "I<value> was greater than B<SEM_VALUE_MAX>."
506 #: build/C/man3/sem_open.3:141
507 msgid "I<name> consists of just \"/\", followed by no other characters."
511 #: build/C/man3/sem_open.3:141
517 #: build/C/man3/sem_open.3:144
518 msgid "The process already has the maximum number of files and open."
522 #: build/C/man3/sem_open.3:144 build/C/man3/sem_unlink.3:54
524 msgid "B<ENAMETOOLONG>"
528 #: build/C/man3/sem_open.3:148 build/C/man3/sem_unlink.3:58
529 msgid "I<name> was too long."
533 #: build/C/man3/sem_open.3:148
539 #: build/C/man3/sem_open.3:151
540 msgid "The system limit on the total number of open files has been reached."
544 #: build/C/man3/sem_open.3:151 build/C/man3/sem_unlink.3:58 build/C/man2/semget.2:197
549 #. this error can occur if we have a name of the (nonportable) form
550 #. /dir/name, and the directory /dev/shm/dir does not exist.
552 #: build/C/man3/sem_open.3:167
554 "The B<O_CREAT> flag was not specified in I<oflag> and no semaphore with this "
555 "I<name> exists; or, B<O_CREAT> was specified, but I<name> wasn't well "
560 #: build/C/man3/sem_open.3:167 build/C/man2/semget.2:205 build/C/man2/semop.2:374
566 #: build/C/man3/sem_open.3:170
567 msgid "Insufficient memory."
571 #: build/C/man3/sem_open.3:179
573 "B<sem_close>(3), B<sem_getvalue>(3), B<sem_post>(3), B<sem_unlink>(3), "
574 "B<sem_wait>(3), B<sem_overview>(7)"
578 #: build/C/man7/sem_overview.7:26
584 #: build/C/man7/sem_overview.7:26
590 #: build/C/man7/sem_overview.7:29
591 msgid "sem_overview - Overview of POSIX semaphores"
595 #: build/C/man7/sem_overview.7:31
596 msgid "POSIX semaphores allow processes and threads to synchronize their actions."
600 #: build/C/man7/sem_overview.7:41
602 "A semaphore is an integer whose value is never allowed to fall below zero. "
603 "Two operations can be performed on semaphores: increment the semaphore value "
604 "by one (B<sem_post>(3)); and decrement the semaphore value by one "
605 "(B<sem_wait>(3)). If the value of a semaphore is currently zero, then a "
606 "B<sem_wait>(3) operation will block until the value becomes greater than "
611 #: build/C/man7/sem_overview.7:44
612 msgid "POSIX semaphores come in two forms: named semaphores and unnamed semaphores."
616 #: build/C/man7/sem_overview.7:44
618 msgid "B<Named semaphores>"
621 #. glibc allows the initial slash to be omitted, and makes
622 #. multiple initial slashes equivalent to a single slash.
623 #. This differs from the implementation of POSIX message queues.
624 #. glibc allows subdirectory components in the name, in which
625 #. case the subdirectory tree must exist under /dev/shm, and
626 #. the fist subdirectory component must exist as the name
627 #. sem.name, and all of the subdirectory components must allow the
628 #. required permissions if a user wants to create a semaphore
629 #. object in a subdirectory.
631 #: build/C/man7/sem_overview.7:64
633 "A named semaphore is identified by a name of the form I</somename>; that is, "
634 "a null-terminated string of up to B<NAME_MAX>I<-4> (i.e., 251) characters "
635 "consisting of an initial slash, followed by one or more characters, none of "
636 "which are slashes. Two processes can operate on the same named semaphore by "
637 "passing the same name to B<sem_open>(3)."
641 #: build/C/man7/sem_overview.7:79
643 "The B<sem_open>(3) function creates a new named semaphore or opens an "
644 "existing named semaphore. After the semaphore has been opened, it can be "
645 "operated on using B<sem_post>(3) and B<sem_wait>(3). When a process has "
646 "finished using the semaphore, it can use B<sem_close>(3) to close the "
647 "semaphore. When all processes have finished using the semaphore, it can be "
648 "removed from the system using B<sem_unlink>(3)."
652 #: build/C/man7/sem_overview.7:79
654 msgid "B<Unnamed semaphores (memory-based semaphores)>"
658 #: build/C/man7/sem_overview.7:94
660 "An unnamed semaphore does not have a name. Instead the semaphore is placed "
661 "in a region of memory that is shared between multiple threads (a "
662 "I<thread-shared semaphore>) or processes (a I<process-shared semaphore>). "
663 "A thread-shared semaphore is placed in an area of memory shared between the "
664 "threads of a process, for example, a global variable. A process-shared "
665 "semaphore must be placed in a shared memory region (e.g., a System V shared "
666 "memory segment created using B<shmget>(2), or a POSIX shared memory object "
667 "built created using B<shm_open>(3))."
671 #: build/C/man7/sem_overview.7:105
673 "Before being used, an unnamed semaphore must be initialized using "
674 "B<sem_init>(3). It can then be operated on using B<sem_post>(3) and "
675 "B<sem_wait>(3). When the semaphore is no longer required, and before the "
676 "memory in which it is located is deallocated, the semaphore should be "
677 "destroyed using B<sem_destroy>(3)."
681 #: build/C/man7/sem_overview.7:108
683 "The remainder of this section describes some specific details of the Linux "
684 "implementation of POSIX semaphores."
688 #: build/C/man7/sem_overview.7:108
694 #: build/C/man7/sem_overview.7:114
696 "Prior to kernel 2.6, Linux only supported unnamed, thread-shared "
697 "semaphores. On a system with Linux 2.6 and a glibc that provides the NPTL "
698 "threading implementation, a complete implementation of POSIX semaphores is "
703 #: build/C/man7/sem_overview.7:114
709 #: build/C/man7/sem_overview.7:119
711 "POSIX named semaphores have kernel persistence: if not removed by "
712 "B<sem_unlink>(3), a semaphore will exist until the system is shut down."
716 #: build/C/man7/sem_overview.7:119
722 #: build/C/man7/sem_overview.7:124
724 "Programs using the POSIX semaphores API must be compiled with I<cc -lrt> to "
725 "link against the real-time library, I<librt>."
729 #: build/C/man7/sem_overview.7:124
731 msgid "Accessing named semaphores via the file system"
735 #: build/C/man7/sem_overview.7:135
737 "On Linux, named semaphores are created in a virtual file system, normally "
738 "mounted under I</dev/shm>, with names of the form B<sem.>I<somename>. (This "
739 "is the reason that semaphore names are limited to B<NAME_MAX>I<-4> rather "
740 "than B<NAME_MAX> characters.)"
744 #: build/C/man7/sem_overview.7:138
746 "Since Linux 2.6.19, ACLs can be placed on files under this directory, to "
747 "control object permissions on a per-user and per-group basis."
751 #: build/C/man7/sem_overview.7:149
753 "System V semaphores (B<semget>(2), B<semop>(2), etc.) are an older semaphore "
754 "API. POSIX semaphores provide a simpler, and better designed interface than "
755 "System V semaphores; on the other hand POSIX semaphores are less widely "
756 "available (especially on older systems) than System V semaphores."
760 #: 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:488
766 #: build/C/man7/sem_overview.7:152
768 "An example of the use of various POSIX semaphore functions is shown in "
773 #: build/C/man7/sem_overview.7:162
775 "B<sem_close>(3), B<sem_destroy>(3), B<sem_getvalue>(3), B<sem_init>(3), "
776 "B<sem_open>(3), B<sem_post>(3), B<sem_unlink>(3), B<sem_wait>(3), "
781 #: build/C/man3/sem_post.3:26
787 #: build/C/man3/sem_post.3:26
793 #: build/C/man3/sem_post.3:29
794 msgid "sem_post - unlock a semaphore"
798 #: build/C/man3/sem_post.3:34
800 msgid "B<int sem_post(sem_t *>I<sem>B<);>\n"
804 #: build/C/man3/sem_post.3:45
806 "B<sem_post>() increments (unlocks) the semaphore pointed to by I<sem>. If "
807 "the semaphore's value consequently becomes greater than zero, then another "
808 "process or thread blocked in a B<sem_wait>(3) call will be woken up and "
809 "proceed to lock the semaphore."
813 #: build/C/man3/sem_post.3:52
815 "B<sem_post>() returns 0 on success; on error, the value of the semaphore is "
816 "left unchanged, -1 is returned, and I<errno> is set to indicate the error."
820 #: build/C/man3/sem_post.3:57
825 #. Added in POSIX.1-2008 TC1 (Austin Interpretation 213)
827 #: build/C/man3/sem_post.3:61
828 msgid "The maximum allowable value for a semaphore would be exceeded."
832 #: build/C/man3/sem_post.3:67
834 "B<sem_post>() is async-signal-safe: it may be safely called within a signal "
839 #: build/C/man3/sem_post.3:70
840 msgid "See B<sem_wait>(3)."
844 #: build/C/man3/sem_post.3:74
845 msgid "B<sem_getvalue>(3), B<sem_wait>(3), B<sem_overview>(7)"
849 #: build/C/man3/sem_unlink.3:26
855 #: build/C/man3/sem_unlink.3:29
856 msgid "sem_unlink - remove a named semaphore"
860 #: build/C/man3/sem_unlink.3:34
862 msgid "B<int sem_unlink(const char *>I<name>B<);>\n"
866 #: build/C/man3/sem_unlink.3:44
868 "B<sem_unlink>() removes the named semaphore referred to by I<name>. The "
869 "semaphore name is removed immediately. The semaphore is destroyed once all "
870 "other processes that have the semaphore open close it."
874 #: build/C/man3/sem_unlink.3:50
876 "On success B<sem_unlink>() returns 0; on error, -1 is returned, with "
877 "I<errno> set to indicate the error."
881 #: build/C/man3/sem_unlink.3:54
882 msgid "The caller does not have permission to unlink this semaphore."
886 #: build/C/man3/sem_unlink.3:62
887 msgid "There is no semaphore with the given I<name>."
891 #: build/C/man3/sem_unlink.3:70
893 "B<sem_getvalue>(3), B<sem_open>(3), B<sem_post>(3), B<sem_wait>(3), "
898 #: build/C/man3/sem_wait.3:26
904 #: build/C/man3/sem_wait.3:26
910 #: build/C/man3/sem_wait.3:29
911 msgid "sem_wait, sem_timedwait, sem_trywait - lock a semaphore"
915 #: build/C/man3/sem_wait.3:34
917 msgid "B<int sem_wait(sem_t *>I<sem>B<);>\n"
921 #: build/C/man3/sem_wait.3:36
923 msgid "B<int sem_trywait(sem_t *>I<sem>B<);>\n"
927 #: build/C/man3/sem_wait.3:38
930 "B<int sem_timedwait(sem_t *>I<sem>B<, const struct timespec "
931 "*>I<abs_timeout>B<);>\n"
935 #: build/C/man3/sem_wait.3:45 build/C/man2/semop.2:51
936 msgid "Feature Test Macro Requirements for glibc (see B<feature_test_macros>(7)):"
940 #: build/C/man3/sem_wait.3:49
942 "B<sem_timedwait>(): _POSIX_C_SOURCE\\ E<gt>=\\ 200112L || _XOPEN_SOURCE\\ "
947 #: build/C/man3/sem_wait.3:59
949 "B<sem_wait>() decrements (locks) the semaphore pointed to by I<sem>. If "
950 "the semaphore's value is greater than zero, then the decrement proceeds, and "
951 "the function returns, immediately. If the semaphore currently has the value "
952 "zero, then the call blocks until either it becomes possible to perform the "
953 "decrement (i.e., the semaphore value rises above zero), or a signal handler "
954 "interrupts the call."
958 #: build/C/man3/sem_wait.3:69
960 "B<sem_trywait>() is the same as B<sem_wait>(), except that if the decrement "
961 "cannot be immediately performed, then call returns an error (I<errno> set to "
962 "B<EAGAIN>) instead of blocking."
966 #: build/C/man3/sem_wait.3:82
968 "B<sem_timedwait>() is the same as B<sem_wait>(), except that I<abs_timeout> "
969 "specifies a limit on the amount of time that the call should block if the "
970 "decrement cannot be immediately performed. The I<abs_timeout> argument "
971 "points to a structure that specifies an absolute timeout in seconds and "
972 "nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). This "
973 "structure is defined as follows:"
977 #: build/C/man3/sem_wait.3:89
980 "struct timespec {\n"
981 " time_t tv_sec; /* Seconds */\n"
982 " long tv_nsec; /* Nanoseconds [0 .. 999999999] */\n"
987 #: build/C/man3/sem_wait.3:100
989 "If the timeout has already expired by the time of the call, and the "
990 "semaphore could not be locked immediately, then B<sem_timedwait>() fails "
991 "with a timeout error (I<errno> set to B<ETIMEDOUT>)."
995 #: build/C/man3/sem_wait.3:108
997 "If the operation can be performed immediately, then B<sem_timedwait>() "
998 "never fails with a timeout error, regardless of the value of "
999 "I<abs_timeout>. Furthermore, the validity of I<abs_timeout> is not checked "
1004 #: build/C/man3/sem_wait.3:114
1006 "All of these functions return 0 on success; on error, the value of the "
1007 "semaphore is left unchanged, -1 is returned, and I<errno> is set to indicate "
1012 #: build/C/man3/sem_wait.3:115 build/C/man2/semop.2:363
1018 #: build/C/man3/sem_wait.3:119
1019 msgid "The call was interrupted by a signal handler; see B<signal>(7)."
1023 #: build/C/man3/sem_wait.3:126
1024 msgid "The following additional error can occur for B<sem_trywait>():"
1028 #: build/C/man3/sem_wait.3:126 build/C/man2/semop.2:338
1034 #: build/C/man3/sem_wait.3:130
1036 "The operation could not be performed without blocking (i.e., the semaphore "
1037 "currently has the value zero)."
1041 #: build/C/man3/sem_wait.3:133
1042 msgid "The following additional errors can occur for B<sem_timedwait>():"
1046 #: build/C/man3/sem_wait.3:138
1048 "The value of I<abs_timeout.tv_nsecs> is less than 0, or greater than or "
1049 "equal to 1000 million."
1053 #: build/C/man3/sem_wait.3:138
1055 msgid "B<ETIMEDOUT>"
1058 #. POSIX.1-2001 also allows EDEADLK -- "A deadlock condition
1059 #. was detected", but this does not occur on Linux(?).
1061 #: build/C/man3/sem_wait.3:143
1062 msgid "The call timed out before the semaphore could be locked."
1065 #. sem_wait() is always interrupted on most other implementations,
1066 #. but on FreeBSD 5.4 SA_RESTART does cause restarting.
1068 #: build/C/man3/sem_wait.3:153
1070 "A signal handler always interrupts a blocked call to one of these functions, "
1071 "regardless of the use of the B<sigaction>(2) B<SA_RESTART> flag."
1075 #: build/C/man3/sem_wait.3:172
1077 "The (somewhat trivial) program shown below operates on an unnamed "
1078 "semaphore. The program expects two command-line arguments. The first "
1079 "argument specifies a seconds value that is used to set an alarm timer to "
1080 "generate a B<SIGALRM> signal. This handler performs a B<sem_post>(3) to "
1081 "increment the semaphore that is being waited on in I<main()> using "
1082 "B<sem_timedwait>(). The second command-line argument specifies the length "
1083 "of the timeout, in seconds, for B<sem_timedwait>(). The following shows "
1084 "what happens on two different runs of the program:"
1088 #: build/C/man3/sem_wait.3:183
1091 "$B< ./a.out 2 3>\n"
1092 "About to call sem_timedwait()\n"
1093 "sem_post() from handler\n"
1094 "sem_getvalue() from handler; value = 1\n"
1095 "sem_timedwait() succeeded\n"
1096 "$B< ./a.out 2 1>\n"
1097 "About to call sem_timedwait()\n"
1098 "sem_timedwait() timed out\n"
1102 #: build/C/man3/sem_wait.3:185
1104 msgid "Program source"
1108 #: build/C/man3/sem_wait.3:196
1111 "#include E<lt>unistd.hE<gt>\n"
1112 "#include E<lt>stdio.hE<gt>\n"
1113 "#include E<lt>stdlib.hE<gt>\n"
1114 "#include E<lt>semaphore.hE<gt>\n"
1115 "#include E<lt>time.hE<gt>\n"
1116 "#include E<lt>assert.hE<gt>\n"
1117 "#include E<lt>errno.hE<gt>\n"
1118 "#include E<lt>signal.hE<gt>\n"
1122 #: build/C/man3/sem_wait.3:198
1124 msgid "sem_t sem;\n"
1128 #: build/C/man3/sem_wait.3:201
1131 "#define handle_error(msg) \\e\n"
1132 " do { perror(msg); exit(EXIT_FAILURE); } while (0)\n"
1136 #: build/C/man3/sem_wait.3:211
1140 "handler(int sig)\n"
1142 " write(STDOUT_FILENO, \"sem_post() from handler\\en\", 24);\n"
1143 " if (sem_post(&sem) == -1) {\n"
1144 " write(STDERR_FILENO, \"sem_post() failed\\en\", 18);\n"
1145 " _exit(EXIT_FAILURE);\n"
1151 #: build/C/man3/sem_wait.3:218
1155 "main(int argc, char *argv[])\n"
1157 " struct sigaction sa;\n"
1158 " struct timespec ts;\n"
1163 #: build/C/man3/sem_wait.3:224
1166 " if (argc != 3) {\n"
1167 " fprintf(stderr, \"Usage: %s E<lt>alarm-secsE<gt> "
1168 "E<lt>wait-secsE<gt>\\en\",\n"
1170 " exit(EXIT_FAILURE);\n"
1175 #: build/C/man3/sem_wait.3:227
1178 " if (sem_init(&sem, 0, 0) == -1)\n"
1179 " handle_error(\"sem_init\");\n"
1183 #: build/C/man3/sem_wait.3:229
1185 msgid " /* Establish SIGALRM handler; set alarm timer using argv[1] */\n"
1189 #: build/C/man3/sem_wait.3:235
1192 " sa.sa_handler = handler;\n"
1193 " sigemptyset(&sa.sa_mask);\n"
1194 " sa.sa_flags = 0;\n"
1195 " if (sigaction(SIGALRM, &sa, NULL) == -1)\n"
1196 " handle_error(\"sigaction\");\n"
1200 #: build/C/man3/sem_wait.3:237
1202 msgid " alarm(atoi(argv[1]));\n"
1206 #: build/C/man3/sem_wait.3:240
1209 " /* Calculate relative interval as current time plus\n"
1210 " number of seconds given argv[2] */\n"
1214 #: build/C/man3/sem_wait.3:243
1217 " if (clock_gettime(CLOCK_REALTIME, &ts) == -1)\n"
1218 " handle_error(\"clock_gettime\");\n"
1222 #: build/C/man3/sem_wait.3:245
1224 msgid " ts.tv_sec += atoi(argv[2]);\n"
1228 #: build/C/man3/sem_wait.3:249
1231 " printf(\"main() about to call sem_timedwait()\\en\");\n"
1232 " while ((s = sem_timedwait(&sem, &ts)) == -1 && errno == EINTR)\n"
1233 " continue; /* Restart if interrupted by handler */\n"
1237 #: build/C/man3/sem_wait.3:251
1239 msgid " /* Check what happened */\n"
1243 #: build/C/man3/sem_wait.3:259
1247 " if (errno == ETIMEDOUT)\n"
1248 " printf(\"sem_timedwait() timed out\\en\");\n"
1250 " perror(\"sem_timedwait\");\n"
1252 " printf(\"sem_timedwait() succeeded\\en\");\n"
1256 #: build/C/man3/sem_wait.3:262
1259 " exit((s == 0) ? EXIT_SUCCESS : EXIT_FAILURE);\n"
1264 #: build/C/man3/sem_wait.3:269
1266 "B<clock_gettime>(2), B<sem_getvalue>(3), B<sem_post>(3), B<sem_overview>(7), "
1271 #: build/C/man2/semctl.2:39
1277 #: build/C/man2/semctl.2:39
1283 #: build/C/man2/semctl.2:42
1284 msgid "semctl - semaphore control operations"
1288 #: build/C/man2/semctl.2:47 build/C/man2/semget.2:42 build/C/man2/semop.2:41
1291 "B<#include E<lt>sys/types.hE<gt>>\n"
1292 "B<#include E<lt>sys/ipc.hE<gt>>\n"
1293 "B<#include E<lt>sys/sem.hE<gt>>\n"
1297 #: build/C/man2/semctl.2:49
1299 msgid "B<int semctl(int >I<semid>B<, int >I<semnum>B<, int >I<cmd>B<, ...);>\n"
1303 #: build/C/man2/semctl.2:60
1305 "B<semctl>() performs the control operation specified by I<cmd> on the "
1306 "semaphore set identified by I<semid>, or on the I<semnum>-th semaphore of "
1307 "that set. (The semaphores in a set are numbered starting at 0.)"
1311 #: build/C/man2/semctl.2:66
1313 "This function has three or four arguments, depending on I<cmd>. When there "
1314 "are four, the fourth has the type I<union semun>. The I<calling program> "
1315 "must define this union as follows:"
1319 #: build/C/man2/semctl.2:76
1323 " int val; /* Value for SETVAL */\n"
1324 " struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */\n"
1325 " unsigned short *array; /* Array for GETALL, SETALL */\n"
1326 " struct seminfo *__buf; /* Buffer for IPC_INFO\n"
1327 " (Linux-specific) */\n"
1332 #: build/C/man2/semctl.2:82
1334 "The I<semid_ds> data structure is defined in I<E<lt>sys/sem.hE<gt>> as "
1339 #: build/C/man2/semctl.2:91
1342 "struct semid_ds {\n"
1343 " struct ipc_perm sem_perm; /* Ownership and permissions */\n"
1344 " time_t sem_otime; /* Last semop time */\n"
1345 " time_t sem_ctime; /* Last change time */\n"
1346 " unsigned short sem_nsems; /* No. of semaphores in set */\n"
1351 #: build/C/man2/semctl.2:99
1353 "The I<ipc_perm> structure is defined in I<E<lt>sys/ipc.hE<gt>> as follows "
1354 "(the highlighted fields are settable using B<IPC_SET>):"
1358 #: build/C/man2/semctl.2:111
1361 "struct ipc_perm {\n"
1362 " key_t __key; /* Key supplied to semget(2) */\n"
1363 " uid_t B<uid>; /* Effective UID of owner */\n"
1364 " gid_t B<gid>; /* Effective GID of owner */\n"
1365 " uid_t cuid; /* Effective UID of creator */\n"
1366 " gid_t cgid; /* Effective GID of creator */\n"
1367 " unsigned short B<mode>; /* Permissions */\n"
1368 " unsigned short __seq; /* Sequence number */\n"
1373 #: build/C/man2/semctl.2:117
1374 msgid "Valid values for I<cmd> are:"
1378 #: build/C/man2/semctl.2:117
1384 #: build/C/man2/semctl.2:129
1386 "Copy information from the kernel data structure associated with I<semid> "
1387 "into the I<semid_ds> structure pointed to by I<arg.buf>. The argument "
1388 "I<semnum> is ignored. The calling process must have read permission on the "
1393 #: build/C/man2/semctl.2:129
1399 #: build/C/man2/semctl.2:152
1401 "Write the values of some members of the I<semid_ds> structure pointed to by "
1402 "I<arg.buf> to the kernel data structure associated with this semaphore set, "
1403 "updating also its I<sem_ctime> member. The following members of the "
1404 "structure are updated: I<sem_perm.uid>, I<sem_perm.gid>, and (the least "
1405 "significant 9 bits of) I<sem_perm.mode>. The effective UID of the calling "
1406 "process must match the owner (I<sem_perm.uid>) or creator "
1407 "(I<sem_perm.cuid>) of the semaphore set, or the caller must be privileged. "
1408 "The argument I<semnum> is ignored."
1412 #: build/C/man2/semctl.2:152
1418 #: build/C/man2/semctl.2:167
1420 "Immediately remove the semaphore set, awakening all processes blocked in "
1421 "B<semop>(2) calls on the set (with an error return and I<errno> set to "
1422 "B<EIDRM>). The effective user ID of the calling process must match the "
1423 "creator or owner of the semaphore set, or the caller must be privileged. "
1424 "The argument I<semnum> is ignored."
1428 #: build/C/man2/semctl.2:167
1430 msgid "B<IPC_INFO> (Linux-specific)"
1434 #: build/C/man2/semctl.2:179
1436 "Returns information about system-wide semaphore limits and parameters in the "
1437 "structure pointed to by I<arg.__buf>. This structure is of type I<seminfo>, "
1438 "defined in I<E<lt>sys/sem.hE<gt>> if the B<_GNU_SOURCE> feature test macro "
1443 #: build/C/man2/semctl.2:201
1446 "struct seminfo {\n"
1447 " int semmap; /* Number of entries in semaphore\n"
1448 " map; unused within kernel */\n"
1449 " int semmni; /* Maximum number of semaphore sets */\n"
1450 " int semmns; /* Maximum number of semaphores in all\n"
1451 " semaphore sets */\n"
1452 " int semmnu; /* System-wide maximum number of undo\n"
1453 " structures; unused within kernel */\n"
1454 " int semmsl; /* Maximum number of semaphores in a\n"
1456 " int semopm; /* Maximum number of operations for\n"
1458 " int semume; /* Maximum number of undo entries per\n"
1459 " process; unused within kernel */\n"
1460 " int semusz; /* Size of struct sem_undo */\n"
1461 " int semvmx; /* Maximum semaphore value */\n"
1462 " int semaem; /* Max. value that can be recorded for\n"
1463 " semaphore adjustment (SEM_UNDO) */\n"
1468 #: build/C/man2/semctl.2:215
1470 "The I<semmsl>, I<semmns>, I<semopm>, and I<semmni> settings can be changed "
1471 "via I</proc/sys/kernel/sem>; see B<proc>(5) for details."
1475 #: build/C/man2/semctl.2:215
1477 msgid "B<SEM_INFO> (Linux-specific)"
1481 #: build/C/man2/semctl.2:229
1483 "Returns a I<seminfo> structure containing the same information as for "
1484 "B<IPC_INFO>, except that the following fields are returned with information "
1485 "about system resources consumed by semaphores: the I<semusz> field returns "
1486 "the number of semaphore sets that currently exist on the system; and the "
1487 "I<semaem> field returns the total number of semaphores in all semaphore sets "
1492 #: build/C/man2/semctl.2:229
1494 msgid "B<SEM_STAT> (Linux-specific)"
1498 #: build/C/man2/semctl.2:240
1500 "Returns a I<semid_ds> structure as for B<IPC_STAT>. However, the I<semid> "
1501 "argument is not a semaphore identifier, but instead an index into the "
1502 "kernel's internal array that maintains information about all semaphore sets "
1507 #: build/C/man2/semctl.2:240
1513 #: build/C/man2/semctl.2:251
1515 "Return B<semval> (i.e., the current value) for all semaphores of the set "
1516 "into I<arg.array>. The argument I<semnum> is ignored. The calling process "
1517 "must have read permission on the semaphore set."
1521 #: build/C/man2/semctl.2:251 build/C/man2/semctl.2:349
1527 #: build/C/man2/semctl.2:264
1529 "The system call returns the value of B<semncnt> for the I<semnum>-th "
1530 "semaphore of the set (i.e., the number of processes waiting for an increase "
1531 "of B<semval> for the I<semnum>-th semaphore of the set). The calling "
1532 "process must have read permission on the semaphore set."
1536 #: build/C/man2/semctl.2:264 build/C/man2/semctl.2:353
1542 #: build/C/man2/semctl.2:277
1544 "The system call returns the value of B<sempid> for the I<semnum>-th "
1545 "semaphore of the set (i.e., the PID of the process that executed the last "
1546 "B<semop>(2) call for the I<semnum>-th semaphore of the set). The calling "
1547 "process must have read permission on the semaphore set."
1551 #: build/C/man2/semctl.2:277 build/C/man2/semctl.2:357
1557 #: build/C/man2/semctl.2:285
1559 "The system call returns the value of B<semval> for the I<semnum>-th "
1560 "semaphore of the set. The calling process must have read permission on the "
1565 #: build/C/man2/semctl.2:285 build/C/man2/semctl.2:361
1571 #: build/C/man2/semctl.2:298
1573 "The system call returns the value of B<semzcnt> for the I<semnum>-th "
1574 "semaphore of the set (i.e., the number of processes waiting for B<semval> of "
1575 "the I<semnum>-th semaphore of the set to become 0). The calling process "
1576 "must have read permission on the semaphore set."
1580 #: build/C/man2/semctl.2:298
1586 #: build/C/man2/semctl.2:320
1588 "Set B<semval> for all semaphores of the set using I<arg.array>, updating "
1589 "also the I<sem_ctime> member of the I<semid_ds> structure associated with "
1590 "the set. Undo entries (see B<semop>(2)) are cleared for altered semaphores "
1591 "in all processes. If the changes to semaphore values would permit blocked "
1592 "B<semop>(2) calls in other processes to proceed, then those processes are "
1593 "woken up. The argument I<semnum> is ignored. The calling process must have "
1594 "alter (write) permission on the semaphore set."
1598 #: build/C/man2/semctl.2:320
1604 #: build/C/man2/semctl.2:338
1606 "Set the value of B<semval> to I<arg.val> for the I<semnum>-th semaphore of "
1607 "the set, updating also the I<sem_ctime> member of the I<semid_ds> structure "
1608 "associated with the set. Undo entries are cleared for altered semaphores in "
1609 "all processes. If the changes to semaphore values would permit blocked "
1610 "B<semop>(2) calls in other processes to proceed, then those processes are "
1611 "woken up. The calling process must have alter permission on the semaphore "
1616 #: build/C/man2/semctl.2:345
1617 msgid "On failure B<semctl>() returns -1 with I<errno> indicating the error."
1621 #: build/C/man2/semctl.2:349
1623 "Otherwise the system call returns a nonnegative value depending on I<cmd> as "
1628 #: build/C/man2/semctl.2:353
1629 msgid "the value of B<semncnt>."
1633 #: build/C/man2/semctl.2:357
1634 msgid "the value of B<sempid>."
1638 #: build/C/man2/semctl.2:361
1639 msgid "the value of B<semval>."
1643 #: build/C/man2/semctl.2:365
1644 msgid "the value of B<semzcnt>."
1648 #: build/C/man2/semctl.2:365
1654 #: build/C/man2/semctl.2:373
1656 "the index of the highest used entry in the kernel's internal array recording "
1657 "information about all semaphore sets. (This information can be used with "
1658 "repeated B<SEM_STAT> operations to obtain information about all semaphore "
1659 "sets on the system.)"
1663 #: build/C/man2/semctl.2:373
1669 #: build/C/man2/semctl.2:377
1670 msgid "As for B<IPC_INFO>."
1674 #: build/C/man2/semctl.2:377
1680 #: build/C/man2/semctl.2:381
1681 msgid "the identifier of the semaphore set whose index was given in I<semid>."
1685 #: build/C/man2/semctl.2:385
1686 msgid "All other I<cmd> values return 0 on success."
1690 #: build/C/man2/semctl.2:389
1691 msgid "On failure, I<errno> will be set to one of the following:"
1695 #: build/C/man2/semctl.2:408
1697 "The argument I<cmd> has one of the values B<GETALL>, B<GETPID>, B<GETVAL>, "
1698 "B<GETNCNT>, B<GETZCNT>, B<IPC_STAT>, B<SEM_STAT>, B<SETALL>, or B<SETVAL> "
1699 "and the calling process does not have the required permissions on the "
1700 "semaphore set and does not have the B<CAP_IPC_OWNER> capability."
1704 #: build/C/man2/semctl.2:408 build/C/man2/semop.2:347
1710 #: build/C/man2/semctl.2:415
1711 msgid "The address pointed to by I<arg.buf> or I<arg.array> isn't accessible."
1715 #: build/C/man2/semctl.2:415 build/C/man2/semop.2:360
1721 #: build/C/man2/semctl.2:418 build/C/man2/semop.2:363
1722 msgid "The semaphore set was removed."
1726 #: build/C/man2/semctl.2:429
1728 "Invalid value for I<cmd> or I<semid>. Or: for a B<SEM_STAT> operation, the "
1729 "index value specified in I<semid> referred to an array slot that is "
1734 #: build/C/man2/semctl.2:429
1740 #: build/C/man2/semctl.2:447
1742 "The argument I<cmd> has the value B<IPC_SET> or B<IPC_RMID> but the "
1743 "effective user ID of the calling process is not the creator (as found in "
1744 "I<sem_perm.cuid>) or the owner (as found in I<sem_perm.uid>) of the "
1745 "semaphore set, and the process does not have the B<CAP_SYS_ADMIN> "
1750 #: build/C/man2/semctl.2:447 build/C/man2/semop.2:382
1756 #: build/C/man2/semctl.2:460
1758 "The argument I<cmd> has the value B<SETALL> or B<SETVAL> and the value to "
1759 "which B<semval> is to be set (for some semaphore of the set) is less than 0 "
1760 "or greater than the implementation limit B<SEMVMX>."
1763 #. SVr4 documents additional error conditions EINVAL, EFBIG, ENOSPC.
1765 #: build/C/man2/semctl.2:463 build/C/man2/semget.2:221 build/C/man2/semop.2:400
1766 msgid "SVr4, POSIX.1-2001."
1770 #: build/C/man2/semctl.2:474
1772 "The B<IPC_INFO>, B<SEM_STAT> and B<SEM_INFO> operations are used by the "
1773 "B<ipcs>(1) program to provide information on allocated resources. In the "
1774 "future these may modified or moved to a /proc file system interface."
1778 #: build/C/man2/semctl.2:487
1780 "Various fields in a I<struct semid_ds> were typed as I<short> under Linux "
1781 "2.2 and have become I<long> under Linux 2.4. To take advantage of this, a "
1782 "recompilation under glibc-2.1.91 or later should suffice. (The kernel "
1783 "distinguishes old and new calls by an B<IPC_64> flag in I<cmd>.)"
1787 #: build/C/man2/semctl.2:496
1789 "In some earlier versions of glibc, the I<semun> union was defined in "
1790 "I<E<lt>sys/sem.hE<gt>>, but POSIX.1-2001 requires that the caller define "
1791 "this union. On versions of glibc where this union is I<not> defined, the "
1792 "macro B<_SEM_SEMUN_UNDEFINED> is defined in I<E<lt>sys/sem.hE<gt>>."
1796 #: build/C/man2/semctl.2:500
1797 msgid "The following system limit on semaphore sets affects a B<semctl>() call:"
1801 #: build/C/man2/semctl.2:500 build/C/man2/semop.2:446
1807 #: build/C/man2/semctl.2:505
1808 msgid "Maximum value for B<semval>: implementation dependent (32767)."
1812 #: build/C/man2/semctl.2:509
1814 "For greater portability it is best to always call B<semctl>() with four "
1819 #: build/C/man2/semctl.2:516
1821 "B<ipc>(2), B<semget>(2), B<semop>(2), B<capabilities>(7), "
1822 "B<sem_overview>(7), B<svipc>(7)"
1826 #: build/C/man2/semget.2:34
1832 #: build/C/man2/semget.2:34
1838 #: build/C/man2/semget.2:37
1839 msgid "semget - get a semaphore set identifier"
1843 #: build/C/man2/semget.2:47
1844 msgid "B<int semget(key_t >I<key>B<,> B<int >I<nsems>B<,> B<int >I<semflg>B<);>"
1848 #: build/C/man2/semget.2:65
1850 "The B<semget>() system call returns the semaphore set identifier associated "
1851 "with the argument I<key>. A new set of I<nsems> semaphores is created if "
1852 "I<key> has the value B<IPC_PRIVATE> or if no existing semaphore set is "
1853 "associated with I<key> and B<IPC_CREAT> is specified in I<semflg>."
1857 #: build/C/man2/semget.2:84
1859 "If I<semflg> specifies both B<IPC_CREAT> and B<IPC_EXCL> and a semaphore set "
1860 "already exists for I<key>, then B<semget>() fails with I<errno> set to "
1861 "B<EEXIST>. (This is analogous to the effect of the combination B<O_CREAT | "
1862 "O_EXCL> for B<open>(2).)"
1866 #: build/C/man2/semget.2:97
1868 "Upon creation, the least significant 9 bits of the argument I<semflg> define "
1869 "the permissions (for owner, group and others) for the semaphore set. These "
1870 "bits have the same format, and the same meaning, as the I<mode> argument of "
1871 "B<open>(2) (though the execute permissions are not meaningful for "
1872 "semaphores, and write permissions mean permission to alter semaphore "
1876 #. In truth, every one of the many implementations that I've tested sets
1877 #. the values to zero, but I suppose there is/was some obscure
1878 #. implementation out there that does not.
1880 #: build/C/man2/semget.2:107
1882 "The values of the semaphores in a newly created set are indeterminate. "
1883 "(POSIX.1-2001 is explicit on this point.) Although Linux, like many other "
1884 "implementations, initializes the semaphore values to 0, a portable "
1885 "application cannot rely on this: it should explicitly initialize the "
1886 "semaphores to the desired values."
1890 #: build/C/man2/semget.2:115
1892 "When creating a new semaphore set, B<semget>() initializes the set's "
1893 "associated data structure, I<semid_ds> (see B<semctl>(2)), as follows:"
1897 #: build/C/man2/semget.2:120
1899 "I<sem_perm.cuid> and I<sem_perm.uid> are set to the effective user ID of the "
1904 #: build/C/man2/semget.2:125
1906 "I<sem_perm.cgid> and I<sem_perm.gid> are set to the effective group ID of "
1907 "the calling process."
1911 #: build/C/man2/semget.2:130
1913 "The least significant 9 bits of I<sem_perm.mode> are set to the least "
1914 "significant 9 bits of I<semflg>."
1918 #: build/C/man2/semget.2:134
1919 msgid "I<sem_nsems> is set to the value of I<nsems>."
1923 #: build/C/man2/semget.2:137
1924 msgid "I<sem_otime> is set to 0."
1928 #: build/C/man2/semget.2:140
1929 msgid "I<sem_ctime> is set to the current time."
1933 #: build/C/man2/semget.2:151
1935 "The argument I<nsems> can be 0 (a don't care) when a semaphore set is not "
1936 "being created. Otherwise I<nsems> must be greater than 0 and less than or "
1937 "equal to the maximum number of semaphores per semaphore set (B<SEMMSL>)."
1940 #. and a check is made to see if it is marked for destruction.
1942 #: build/C/man2/semget.2:155
1943 msgid "If the semaphore set already exists, the permissions are verified."
1947 #: build/C/man2/semget.2:161
1949 "If successful, the return value will be the semaphore set identifier (a "
1950 "nonnegative integer), otherwise -1 is returned, with I<errno> indicating the "
1955 #: build/C/man2/semget.2:165
1956 msgid "On failure I<errno> will be set to one of the following:"
1960 #: build/C/man2/semget.2:173
1962 "A semaphore set exists for I<key>, but the calling process does not have "
1963 "permission to access the set, and does not have the B<CAP_IPC_OWNER> "
1969 #. The semaphore set is marked to be deleted.
1971 #: build/C/man2/semget.2:186
1973 "A semaphore set exists for I<key> and I<semflg> specified both B<IPC_CREAT> "
1978 #: build/C/man2/semget.2:197
1980 "I<nsems> is less than 0 or greater than the limit on the number of "
1981 "semaphores per semaphore set (B<SEMMSL>), or a semaphore set corresponding "
1982 "to I<key> already exists, and I<nsems> is larger than the number of "
1983 "semaphores in that set."
1987 #: build/C/man2/semget.2:205
1989 "No semaphore set exists for I<key> and I<semflg> did not specify "
1994 #: build/C/man2/semget.2:209
1996 "A semaphore set has to be created but the system does not have enough memory "
1997 "for the new data structure."
2001 #: build/C/man2/semget.2:209
2007 #: build/C/man2/semget.2:217
2009 "A semaphore set has to be created but the system limit for the maximum "
2010 "number of semaphore sets (B<SEMMNI>), or the system wide maximum number of "
2011 "semaphores (B<SEMMNS>), would be exceeded."
2015 #: build/C/man2/semget.2:231
2017 "B<IPC_PRIVATE> isn't a flag field but a I<key_t> type. If this special "
2018 "value is used for I<key>, the system call ignores everything but the least "
2019 "significant 9 bits of I<semflg> and creates a new semaphore set (on "
2024 #: build/C/man2/semget.2:235
2026 "The following limits on semaphore set resources affect the B<semget>() "
2031 #: build/C/man2/semget.2:235
2036 #. This /proc file is not available in Linux 2.2 and earlier -- MTK
2038 #: build/C/man2/semget.2:241
2040 "System wide maximum number of semaphore sets: policy dependent (on Linux, "
2041 "this limit can be read and modified via the fourth field of "
2042 "I</proc/sys/kernel/sem>)."
2046 #: build/C/man2/semget.2:241
2052 #: build/C/man2/semget.2:246
2054 "Maximum number of semaphores per semid: implementation dependent (on Linux, "
2055 "this limit can be read and modified via the first field of "
2056 "I</proc/sys/kernel/sem>)."
2060 #: build/C/man2/semget.2:246
2066 #: build/C/man2/semget.2:254
2068 "System wide maximum number of semaphores: policy dependent (on Linux, this "
2069 "limit can be read and modified via the second field of "
2070 "I</proc/sys/kernel/sem>). Values greater than B<SEMMSL * SEMMNI> makes it "
2075 #: build/C/man2/semget.2:254 build/C/man2/semop.2:458
2081 #: build/C/man2/semget.2:260
2083 "The name choice B<IPC_PRIVATE> was perhaps unfortunate, B<IPC_NEW> would "
2084 "more clearly show its function."
2087 #. In fact they are initialized to zero on Linux, but POSIX.1-2001
2088 #. does not specify this, and we can't portably rely on it.
2090 #: build/C/man2/semget.2:279
2092 "The semaphores in a set are not initialized by B<semget>(). In order to "
2093 "initialize the semaphores, B<semctl>(2) must be used to perform a B<SETVAL> "
2094 "or a B<SETALL> operation on the semaphore set. (Where multiple peers do not "
2095 "know who will be the first to initialize the set, checking for a nonzero "
2096 "I<sem_otime> in the associated data structure retrieved by a B<semctl>(2) "
2097 "B<IPC_STAT> operation can be used to avoid races.)"
2101 #: build/C/man2/semget.2:286
2103 "B<semctl>(2), B<semop>(2), B<ftok>(3), B<capabilities>(7), "
2104 "B<sem_overview>(7), B<svipc>(7)"
2108 #: build/C/man2/semop.2:33
2114 #: build/C/man2/semop.2:33
2120 #: build/C/man2/semop.2:36
2121 msgid "semop, semtimedop - semaphore operations"
2125 #: build/C/man2/semop.2:43
2128 "B<int semop(int >I<semid>B<, struct sembuf *>I<sops>B<, unsigned "
2133 #: build/C/man2/semop.2:46
2136 "B<int semtimedop(int >I<semid>B<, struct sembuf *>I<sops>B<, unsigned "
2138 "B< struct timespec *>I<timeout>B<);>\n"
2142 #: build/C/man2/semop.2:55
2143 msgid "B<semtimedop>(): _GNU_SOURCE"
2147 #: build/C/man2/semop.2:57
2148 msgid "Each semaphore in a semaphore set has the following associated values:"
2152 #: build/C/man2/semop.2:64
2155 "unsigned short semval; /* semaphore value */\n"
2156 "unsigned short semzcnt; /* # waiting for zero */\n"
2157 "unsigned short semncnt; /* # waiting for increase */\n"
2158 "pid_t sempid; /* process that did last op */\n"
2162 #: build/C/man2/semop.2:78
2164 "B<semop>() performs operations on selected semaphores in the set indicated "
2165 "by I<semid>. Each of the I<nsops> elements in the array pointed to by "
2166 "I<sops> specifies an operation to be performed on a single semaphore. The "
2167 "elements of this structure are of type I<struct sembuf>, containing the "
2168 "following members:"
2172 #: build/C/man2/semop.2:84
2175 "unsigned short sem_num; /* semaphore number */\n"
2176 "short sem_op; /* semaphore operation */\n"
2177 "short sem_flg; /* operation flags */\n"
2181 #: build/C/man2/semop.2:96
2183 "Flags recognized in I<sem_flg> are B<IPC_NOWAIT> and B<SEM_UNDO>. If an "
2184 "operation specifies B<SEM_UNDO>, it will be automatically undone when the "
2185 "process terminates."
2189 #: build/C/man2/semop.2:111
2191 "The set of operations contained in I<sops> is performed in I<array order>, "
2192 "and I<atomically>, that is, the operations are performed either as a "
2193 "complete unit, or not at all. The behavior of the system call if not all "
2194 "operations can be performed immediately depends on the presence of the "
2195 "B<IPC_NOWAIT> flag in the individual I<sem_flg> fields, as noted below."
2199 #: build/C/man2/semop.2:118
2201 "Each operation is performed on the I<sem_num>-th semaphore of the semaphore "
2202 "set, where the first semaphore of the set is numbered 0. There are three "
2203 "types of operation, distinguished by the value of I<sem_op>."
2207 #: build/C/man2/semop.2:131
2209 "If I<sem_op> is a positive integer, the operation adds this value to the "
2210 "semaphore value (I<semval>). Furthermore, if B<SEM_UNDO> is specified for "
2211 "this operation, the system updates the process undo count (I<semadj>) for "
2212 "this semaphore. This operation can always proceed\\(emit never forces a "
2213 "process to wait. The calling process must have alter permission on the "
2218 #: build/C/man2/semop.2:156
2220 "If I<sem_op> is zero, the process must have read permission on the semaphore "
2221 "set. This is a \"wait-for-zero\" operation: if I<semval> is zero, the "
2222 "operation can immediately proceed. Otherwise, if B<IPC_NOWAIT> is specified "
2223 "in I<sem_flg>, B<semop>() fails with I<errno> set to B<EAGAIN> (and none of "
2224 "the operations in I<sops> is performed). Otherwise I<semzcnt> (the count of "
2225 "processes waiting until this semaphore's value becomes zero) is incremented "
2226 "by one and the process sleeps until one of the following occurs:"
2230 #: build/C/man2/semop.2:156 build/C/man2/semop.2:161 build/C/man2/semop.2:169 build/C/man2/semop.2:179 build/C/man2/semop.2:230 build/C/man2/semop.2:245 build/C/man2/semop.2:252 build/C/man2/semop.2:262
2236 #: build/C/man2/semop.2:161
2237 msgid "I<semval> becomes 0, at which time the value of I<semzcnt> is decremented."
2241 #: build/C/man2/semop.2:169
2243 "The semaphore set is removed: B<semop>() fails, with I<errno> set to "
2248 #: build/C/man2/semop.2:179
2250 "The calling process catches a signal: the value of I<semzcnt> is decremented "
2251 "and B<semop>() fails, with I<errno> set to B<EINTR>."
2255 #: build/C/man2/semop.2:190
2257 "The time limit specified by I<timeout> in a B<semtimedop>() call expires: "
2258 "B<semop>() fails, with I<errno> set to B<EAGAIN>."
2262 #: build/C/man2/semop.2:230
2264 "If I<sem_op> is less than zero, the process must have alter permission on "
2265 "the semaphore set. If I<semval> is greater than or equal to the absolute "
2266 "value of I<sem_op>, the operation can proceed immediately: the absolute "
2267 "value of I<sem_op> is subtracted from I<semval>, and, if B<SEM_UNDO> is "
2268 "specified for this operation, the system updates the process undo count "
2269 "(I<semadj>) for this semaphore. If the absolute value of I<sem_op> is "
2270 "greater than I<semval>, and B<IPC_NOWAIT> is specified in I<sem_flg>, "
2271 "B<semop>() fails, with I<errno> set to B<EAGAIN> (and none of the "
2272 "operations in I<sops> is performed). Otherwise I<semncnt> (the counter of "
2273 "processes waiting for this semaphore's value to increase) is incremented by "
2274 "one and the process sleeps until one of the following occurs:"
2278 #: build/C/man2/semop.2:245
2280 "I<semval> becomes greater than or equal to the absolute value of I<sem_op>, "
2281 "at which time the value of I<semncnt> is decremented, the absolute value of "
2282 "I<sem_op> is subtracted from I<semval> and, if B<SEM_UNDO> is specified for "
2283 "this operation, the system updates the process undo count (I<semadj>) for "
2288 #: build/C/man2/semop.2:252
2290 "The semaphore set is removed from the system: B<semop>() fails, with "
2291 "I<errno> set to B<EIDRM>."
2295 #: build/C/man2/semop.2:262
2297 "The calling process catches a signal: the value of I<semncnt> is decremented "
2298 "and B<semop>() fails, with I<errno> set to B<EINTR>."
2302 #: build/C/man2/semop.2:271
2304 "The time limit specified by I<timeout> in a B<semtimedop>() call expires: "
2305 "the system call fails, with I<errno> set to B<EAGAIN>."
2311 #: build/C/man2/semop.2:282
2313 "On successful completion, the I<sempid> value for each semaphore specified "
2314 "in the array pointed to by I<sops> is set to the process ID of the calling "
2315 "process. In addition, the I<sem_otime> is set to the current time."
2319 #: build/C/man2/semop.2:309
2321 "B<semtimedop>() behaves identically to B<semop>() except that in those "
2322 "cases were the calling process would sleep, the duration of that sleep is "
2323 "limited by the amount of elapsed time specified by the I<timespec> structure "
2324 "whose address is passed in the I<timeout> argument. If the specified time "
2325 "limit has been reached, B<semtimedop>() fails with I<errno> set to "
2326 "B<EAGAIN> (and none of the operations in I<sops> is performed). If the "
2327 "I<timeout> argument is NULL, then B<semtimedop>() behaves exactly like "
2332 #: build/C/man2/semop.2:319
2334 "If successful B<semop>() and B<semtimedop>() return 0; otherwise they "
2335 "return -1 with I<errno> indicating the error."
2339 #: build/C/man2/semop.2:323
2340 msgid "On failure, I<errno> is set to one of the following:"
2344 #: build/C/man2/semop.2:323
2350 #: build/C/man2/semop.2:331
2352 "The argument I<nsops> is greater than B<SEMOPM>, the maximum number of "
2353 "operations allowed per system call."
2357 #: build/C/man2/semop.2:338
2359 "The calling process does not have the permissions required to perform the "
2360 "specified semaphore operations, and does not have the B<CAP_IPC_OWNER> "
2365 #: build/C/man2/semop.2:347
2367 "An operation could not proceed immediately and either B<IPC_NOWAIT> was "
2368 "specified in I<sem_flg> or the time limit specified in I<timeout> expired."
2372 #: build/C/man2/semop.2:354
2374 "An address specified in either the I<sops> or the I<timeout> argument isn't "
2379 #: build/C/man2/semop.2:354
2385 #: build/C/man2/semop.2:360
2387 "For some operation the value of I<sem_num> is less than 0 or greater than or "
2388 "equal to the number of semaphores in the set."
2392 #: build/C/man2/semop.2:367
2394 "While blocked in this system call, the process caught a signal; see "
2399 #: build/C/man2/semop.2:374
2401 "The semaphore set doesn't exist, or I<semid> is less than zero, or I<nsops> "
2402 "has a nonpositive value."
2406 #: build/C/man2/semop.2:382
2408 "The I<sem_flg> of some operation specified B<SEM_UNDO> and the system does "
2409 "not have enough memory to allocate the undo structure."
2413 #: build/C/man2/semop.2:390
2415 "For some operation I<sem_op+semval> is greater than B<SEMVMX>, the "
2416 "implementation dependent maximum value for I<semval>."
2420 #: build/C/man2/semop.2:390
2426 #: build/C/man2/semop.2:397
2428 "B<semtimedop>() first appeared in Linux 2.5.52, and was subsequently "
2429 "backported into kernel 2.4.22. Glibc support for B<semtimedop>() first "
2430 "appeared in version 2.3.3."
2434 #: build/C/man2/semop.2:408
2436 "The I<sem_undo> structures of a process aren't inherited by the child "
2437 "produced by B<fork>(2), but they are inherited across an B<execve>(2) "
2442 #: build/C/man2/semop.2:414
2444 "B<semop>() is never automatically restarted after being interrupted by a "
2445 "signal handler, regardless of the setting of the B<SA_RESTART> flag when "
2446 "establishing a signal handler."
2450 #: build/C/man2/semop.2:429
2452 "I<semadj> is a per-process integer which is simply the (negative) count of "
2453 "all semaphore operations performed specifying the B<SEM_UNDO> flag. When a "
2454 "semaphore's value is directly set using the B<SETVAL> or B<SETALL> request "
2455 "to B<semctl>(2), the corresponding I<semadj> values in all processes are "
2460 #: build/C/man2/semop.2:434
2462 "The I<semval>, I<sempid>, I<semzcnt>, and I<semnct> values for a semaphore "
2463 "can all be retrieved using appropriate B<semctl>(2) calls."
2467 #: build/C/man2/semop.2:438
2468 msgid "The following limits on semaphore set resources affect the B<semop>() call:"
2472 #: build/C/man2/semop.2:438
2477 #. This /proc file is not available in Linux 2.2 and earlier -- MTK
2479 #: build/C/man2/semop.2:446
2481 "Maximum number of operations allowed for one B<semop>() call (32) (on "
2482 "Linux, this limit can be read and modified via the third field of "
2483 "I</proc/sys/kernel/sem>)."
2487 #: build/C/man2/semop.2:451
2488 msgid "Maximum allowable value for I<semval>: implementation dependent (32767)."
2492 #: build/C/man2/semop.2:458
2494 "The implementation has no intrinsic limits for the adjust on exit maximum "
2495 "value (B<SEMAEM>), the system wide maximum number of undo structures "
2496 "(B<SEMMNU>) and the per-process maximum number of undo entries system "
2501 #: build/C/man2/semop.2:479
2503 "When a process terminates, its set of associated I<semadj> structures is "
2504 "used to undo the effect of all of the semaphore operations it performed with "
2505 "the B<SEM_UNDO> flag. This raises a difficulty: if one (or more) of these "
2506 "semaphore adjustments would result in an attempt to decrease a semaphore's "
2507 "value below zero, what should an implementation do? One possible approach "
2508 "would be to block until all the semaphore adjustments could be performed. "
2509 "This is however undesirable since it could force process termination to "
2510 "block for arbitrarily long periods. Another possibility is that such "
2511 "semaphore adjustments could be ignored altogether (somewhat analogously to "
2512 "failing when B<IPC_NOWAIT> is specified for a semaphore operation). Linux "
2513 "adopts a third approach: decreasing the semaphore value as far as possible "
2514 "(i.e., to zero) and allowing process termination to proceed immediately."
2518 #. http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
2520 #. http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
2522 #: build/C/man2/semop.2:488
2524 "In kernels 2.6.x, x E<lt>= 10, there is a bug that in some circumstances "
2525 "prevents a process that is waiting for a semaphore value to become zero from "
2526 "being woken up when the value does actually become zero. This bug is fixed "
2531 #: build/C/man2/semop.2:493
2533 "The following code segment uses B<semop>() to atomically wait for the value "
2534 "of semaphore 0 to become zero, and then increment the semaphore value by "
2539 #: build/C/man2/semop.2:497
2542 " struct sembuf sops[2];\n"
2547 #: build/C/man2/semop.2:499
2549 msgid " /* Code to set I<semid> omitted */\n"
2553 #: build/C/man2/semop.2:503
2556 " sops[0].sem_num = 0; /* Operate on semaphore 0 */\n"
2557 " sops[0].sem_op = 0; /* Wait for value to equal 0 */\n"
2558 " sops[0].sem_flg = 0;\n"
2562 #: build/C/man2/semop.2:507
2565 " sops[1].sem_num = 0; /* Operate on semaphore 0 */\n"
2566 " sops[1].sem_op = 1; /* Increment value by one */\n"
2567 " sops[1].sem_flg = 0;\n"
2571 #: build/C/man2/semop.2:512
2574 " if (semop(semid, sops, 2) == -1) {\n"
2575 " perror(\"semop\");\n"
2576 " exit(EXIT_FAILURE);\n"
2581 #: build/C/man2/semop.2:521
2583 "B<semctl>(2), B<semget>(2), B<sigaction>(2), B<capabilities>(7), "
2584 "B<sem_overview>(7), B<svipc>(7), B<time>(7)"