OSDN Git Service

2c314af0de735fba6609aeb890c5c7a6d4631a4f
[linuxjm/LDP_man-pages.git] / draft / man2 / semop.2
1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Modified 1996-10-22, Eric S. Raymond <esr@thyrsus.com>
24 .\" Modified 2002-01-08, Michael Kerrisk <mtk.manpages@gmail.com>
25 .\" Modified 2003-04-28, Ernie Petrides <petrides@redhat.com>
26 .\" Modified 2004-05-27, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
28 .\"     Language and formatting clean-ups
29 .\"     Added notes on /proc files
30 .\" 2005-04-08, mtk, Noted kernel version numbers for semtimedop()
31 .\" 2007-07-09, mtk, Added an EXAMPLE code segment.
32 .\"
33 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
34 .\"         all rights reserved.
35 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
36 .\" Updated 2003-02-09, Kentaro Shirakata <argrath@ub32.org>
37 .\" Updated 2003-09-12, Kentaro Shirakata <argrath@ub32.org>
38 .\" Updated 2005-03-01, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
39 .\" Updated 2005-04-17, Akihiro MOTOKI
40 .\" Updated 2005-09-06, Akihiro MOTOKI
41 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
42 .\"
43 .\"WORD:        semaphore               セマフォ
44 .\"WORD:        member                  メンバー
45 .\"WORD:        process                 プロセス
46 .\"WORD:        system call             システムコール
47 .\"WORD:        undo                    アンドゥ
48 .\"WORD:        signal                  シグナル
49 .\"WORD:        catch                   捕獲(catch)
50 .\"WORD:        process-ID              プロセスID
51 .\"WORD:        policy                  方針
52 .\"WORD:        implement               実装
53 .\"WORD:        queue                   キュー
54 .\"WORD:        free                    解放(free).
55 .\"WORD:        memory                  メモリ
56 .\"WORD:        anonymous structure     無名構造体
57 .\"WORD:        time limit              制限時間
58 \"
59 .TH SEMOP 2 2008-10-04 "Linux" "Linux Programmer's Manual"
60 .\"O .SH NAME
61 .SH 名前
62 .\"O semop, semtimedop \- semaphore operations
63 semop, semtimedop \- セマフォの操作
64 .\"O .SH SYNOPSIS
65 .SH 書式
66 .nf
67 .B #include <sys/types.h>
68 .B #include <sys/ipc.h>
69 .B #include <sys/sem.h>
70 .sp
71 .BI "int semop(int " semid ", struct sembuf *" sops ", unsigned " nsops );
72 .sp
73 .BI "int semtimedop(int " semid ", struct sembuf *" sops ", unsigned " nsops ,
74 .BI "               struct timespec *" timeout );
75 .fi
76 .sp
77 .in -4n
78 .\"O Feature Test Macro Requirements for glibc (see
79 .\"O .BR feature_test_macros (7)):
80 glibc 向けの機能検査マクロの要件
81 .RB ( feature_test_macros (7)
82 参照):
83 .in
84 .sp
85 .BR semtimedop ():
86 _GNU_SOURCE
87 .\"O .SH DESCRIPTION
88 .SH 説明
89 .\"O Each semaphore in a semaphore set has the following associated values:
90 セマフォ集合 (semaphore set) のメンバーの各セマフォは
91 以下の関連情報を持っている:
92 .sp
93 .in +4n
94 .nf
95 .\"O unsigned short  semval;   /* semaphore value */
96 .\"O unsigned short  semzcnt;  /* # waiting for zero */
97 .\"O unsigned short  semncnt;  /* # waiting for increase */
98 .\"O pid_t           sempid;   /* process that did last op */
99 unsigned short  semval;   /* セマフォ値 */
100 unsigned short  semzcnt;  /* ゼロを待つプロセス数 */
101 unsigned short  semncnt;  /* 増加を待つプロセス数 */
102 pid_t           sempid;   /* 最後に操作を行なったプロセス */
103 .sp
104 .in -4n
105 .fi
106 .\"O .BR semop ()
107 .\"O performs operations on selected semaphores in the set indicated by
108 .\"O .IR semid .
109 .BR semop ()
110
111 .I semid
112 で指定されたセマフォ集合の選択されたセマフォに対して操作を行う。
113 .\"O Each of the
114 .\"O .I nsops
115 .\"O elements in the array pointed to by
116 .\"O .I sops
117 .\"O specifies an operation to be performed on a single semaphore.
118 .\"O The elements of this structure are of type
119 .\"O .IR "struct sembuf" ,
120 .\"O containing the following members:
121 .I sops
122
123 .I nsops
124 個の要素の配列を指し、配列の各要素は個々のセマフォに
125 対する操作を示す。その型は
126 .I struct sembuf
127 で、次のメンバを持つ:
128 .sp
129 .in +4n
130 .nf
131 .\"O unsigned short sem_num;  /* semaphore number */
132 .\"O short          sem_op;   /* semaphore operation */
133 .\"O short          sem_flg;  /* operation flags */
134 unsigned short sem_num;  /* セマフォ番号 */
135 short          sem_op;   /* セマフォ操作 */
136 short          sem_flg;  /* 操作フラグ */
137 .sp
138 .in -4n
139 .fi
140 .\"O Flags recognized in
141 .\"O .I sem_flg
142 .\"O are
143 .\"O .B IPC_NOWAIT
144 .\"O and
145 .\"O .BR SEM_UNDO .
146 .\"O If an operation specifies
147 .\"O .BR SEM_UNDO ,
148 .\"O it will be automatically undone when the process terminates.
149 .I sem_flg
150 には
151 .B IPC_NOWAIT
152
153 .B SEM_UNDO
154 が設定できる。
155 .B SEM_UNDO
156 が指定された操作は、そのプロセスが終了した時に自動的に取り消される。
157 .PP
158 .\"O The set of operations contained in
159 .\"O .I sops
160 .\"O is performed in
161 .\"O .IR "array order" ,
162 .\"O and
163 .\"O .IR atomically ,
164 .\"O that is, the operations are performed either as a complete unit,
165 .\"O or not at all.
166 .I sops
167 に含まれる操作の集合は、
168 .I "配列の順序"
169 で、
170 .I アトミックに
171 実行される。
172 すなわち、全ての操作が完全に実行されるか、全く実行されないかの
173 どちらかとなる。
174
175 .\"O The behavior of the system call if not all operations can be
176 .\"O performed immediately depends on the presence of the
177 .\"O .B IPC_NOWAIT
178 .\"O flag in the individual
179 .\"O .I sem_flg
180 .\"O fields, as noted below.
181 全ての操作が直ちに実行できない場合のこのシステムコールの振る舞いは
182 個々の操作の
183 .I sem_flg
184 フィールドに
185 .B IPC_NOWAIT
186 が存在するかによって決まり、後述のようになる。
187
188 .\"O Each operation is performed on the
189 .\"O .IR sem_num \-th
190 .\"O semaphore of the semaphore set, where the first semaphore of the set
191 .\"O is numbered 0.
192 それぞれの操作はセマフォ集合の
193 .IR sem_num 番目
194 のセマフォに対して実行される。セマフォ集合の最初のセマフォには
195 番号 0 が振られる。
196 .\"O There are three types of operation, distinguished by the value of
197 .\"O .IR sem_op .
198 そして操作は三種類あり、
199 .I sem_op
200 の値で区別される。
201 .PP
202 .\"O If
203 .\"O .I sem_op
204 .\"O is a positive integer, the operation adds this value to
205 .\"O the semaphore value
206 .\"O .RI  ( semval ).
207 .\"O Furthermore, if
208 .\"O .B SEM_UNDO
209 .\"O is specified for this operation, the system updates the process undo count
210 .\"O .RI ( semadj )
211 .\"O for this semaphore.
212 .\"O This operation can always proceed\(emit never forces a process to wait.
213 .\"O The calling process must have alter permission on the semaphore set.
214 .I sem_op
215 が正の整数の場合、操作としてその値をセマフォの値
216 .RI ( semval )
217 に加える。さらにこの操作に
218 .B SEM_UNDO
219 が指定されている場合は、システムはこのセマフォの プロセス・アンドゥ数
220 .RI ( semadj )
221 を更新する。
222 この操作は必ず実行でき、プロセスの停止は起こらない。
223 呼び出し元プロセスは対象のセマフォ集合を変更する許可がなければならない。
224 .PP
225 .\"O If
226 .\"O .I sem_op
227 .\"O is zero, the process must have read permission on the semaphore
228 .\"O set.
229 .\"O This is a "wait-for-zero" operation: if
230 .\"O .I semval
231 .\"O is zero, the operation can immediately proceed.
232 .I sem_op
233 が 0 の場合、「ゼロまで待つ」操作である。この場合、プロセスは
234 そのセマフォ集合に対する読み込み許可がなければならない。
235 .I semval
236 が 0 ならば、操作は直ちに行われる。
237 .\"O Otherwise, if
238 .\"O .B IPC_NOWAIT
239 .\"O is specified in
240 .\"O .IR sem_flg ,
241 .\"O .BR semop ()
242 .\"O fails with
243 .\"O .I errno
244 .\"O set to
245 .\"O .B EAGAIN
246 .\"O (and none of the operations in
247 .\"O .I sops
248 .\"O is performed).
249 .I semval
250 が 0 でない場合、
251 .I sem_flg
252
253 .B IPC_NOWAIT
254 が指定されていれば、
255 .BR semop ()
256 は失敗し、
257 .B errno
258
259 .B EAGAIN
260 が設定される (このとき
261 .I sops
262 に対する操作は全く実行されない)。
263 .\"O Otherwise
264 .\"O .I semzcnt
265 .\"O (the count of processes waiting until this semaphore's value becomes zero)
266 .\"O is incremented by one and the process sleeps until
267 .\"O one of the following occurs:
268 .I sem_flg
269
270 .B IPC_NOWAIT
271 が指定されていない場合、
272 .I semzcnt
273 (セマフォ値が 0 になるのを待っているプロセスの数) を 1 増加させて、
274 以下のいずれかが起こるまでプロセスを停止 (sleep) する。
275 .IP \(bu 3
276 .\"O .I semval
277 .\"O becomes 0, at which time the value of
278 .\"O .I semzcnt
279 .\"O is decremented.
280 .I semval
281 が 0 になった: このとき
282 .I semzcnt
283 の値は 1 減算される。
284 .IP \(bu
285 .\"O The semaphore set
286 .\"O is removed:
287 .\"O .BR semop ()
288 .\"O fails, with
289 .\"O .I errno
290 .\"O set to
291 .\"O .BR EIDRM .
292 セマフォ集合が削除された: このとき
293 .BR semop ()
294 は失敗し、
295 .I errno
296
297 .B EIDRM
298 が設定される。
299 .IP \(bu
300 .\"O The calling process catches a signal:
301 .\"O the value of
302 .\"O .I semzcnt
303 .\"O is decremented and
304 .\"O .BR semop ()
305 .\"O fails, with
306 .\"O .I errno
307 .\"O set to
308 .\"O .BR EINTR .
309 呼び出し元プロセスがシグナルを捕獲した: このとき
310 .I semzcnt
311 の値は 1 減算され、
312 .BR semop ()
313 は失敗し
314 .I errno
315
316 .B EINTR
317 が設定される。
318 .IP \(bu
319 .\"O The time limit specified by
320 .\"O .I timeout
321 .\"O in a
322 .\"O .BR semtimedop ()
323 .\"O call expires:
324 .\"O .BR semop ()
325 .\"O fails, with
326 .\"O .I errno
327 .\"O set to
328 .\"O .BR EAGAIN .
329 .\" motoki: semop () は semtimedop () の間違い?
330 .BR semtimedop ()
331
332 .I timeout
333 で指定された制限時間が経過した: このとき
334 .BR semtimedop ()
335 は失敗し、
336 .I errno
337
338 .B EAGAIN
339 が設定される。
340 .PP
341 .\"O If
342 .\"O .I sem_op
343 .\"O is less than zero, the process must have alter permission on the
344 .\"O semaphore set.
345 .\"O If
346 .\"O .I semval
347 .\"O is greater than or equal to the absolute value of
348 .\"O .IR sem_op ,
349 .\"O the operation can proceed immediately:
350 .\"O the absolute value of
351 .\"O .I sem_op
352 .\"O is subtracted from
353 .\"O .IR semval ,
354 .\"O and, if
355 .\"O .B SEM_UNDO
356 .\"O is specified for this operation, the system updates the process undo count
357 .\"O .RI ( semadj )
358 .\"O for this semaphore.
359 .I sem_op
360 が 0 未満の場合、プロセスにはそのセマフォ集合を変更する許可がなければ
361 ならない。
362 .I semval
363
364 .I sem_op
365 の絶対値以上の場合は、操作は直ちに実行される:
366 .I semval
367 から
368 .I sem_op
369 の絶対値が減算される。
370 さらに、この操作に
371 .B SEM_UNDO
372 が指定されている場合は、このセマフォのプロセス・アンドゥ数
373 .RI ( semadj )
374 を更新する。
375 .\"O If the absolute value of
376 .\"O .I sem_op
377 .\"O is greater than
378 .\"O .IR semval ,
379 .\"O and
380 .\"O .B IPC_NOWAIT
381 .\"O is specified in
382 .\"O .IR sem_flg ,
383 .\"O .BR semop ()
384 .\"O fails, with
385 .\"O .I errno
386 .\"O set to
387 .\"O .B EAGAIN
388 .\"O (and none of the operations in
389 .\"O .I sops
390 .\"O is performed).
391 .I semval
392
393 .I sem_op
394 の絶対値より小さく、
395 .I sem_flg
396
397 .B IPC_NOWAIT
398 が指定された場合は、
399 .BR semop ()
400 は失敗し、
401 .I errno
402
403 .B EAGAIN
404 が設定される (このとき
405 .I sops
406 の操作は全く実行されない)。
407 .\"O Otherwise
408 .\"O .I semncnt
409 .\"O (the counter of processes waiting for this semaphore's value to increase)
410 .\"O is incremented by one and the process sleeps until
411 .\"O one of the following occurs:
412 .B IPC_WAIT
413 が指定されていなければ、
414 .I semncnt
415 (このセマフォの値が増加するのを待っているプロセス数のカウンタ)
416 を 1 増加させて、以下のいずれかが起こるまでプロセスを停止 (sleep) する。
417 .IP \(bu 3
418 .\"O .I semval
419 .\"O becomes greater than or equal to the absolute value of
420 .\"O .IR sem_op ,
421 .\"O at which time the value of
422 .\"O .I semncnt
423 .\"O is decremented, the absolute value of
424 .\"O .I sem_op
425 .\"O is subtracted from
426 .\"O .I semval
427 .\"O and, if
428 .\"O .B SEM_UNDO
429 .\"O is specified for this operation, the system updates the process undo count
430 .\"O .RI ( semadj )
431 .\"O for this semaphore.
432 .I semval
433
434 .I sem_op
435 の絶対値以上になった: このとき
436 .I semncnt
437 が 1 減算され、
438 .I semval
439 から
440 .I sem_op
441 の絶対値が引かれる。
442 この操作に
443 .B SEM_UNDO
444 が指定されていた場合にはこのセマフォのプロセス・アンドゥ数
445 .RI ( semadj )
446 も更新する。
447 .IP \(bu
448 .\"O The semaphore set is removed from the system:
449 .\"O .BR semop ()
450 .\"O fails, with
451 .\"O .I errno
452 .\"O set to
453 .\"O .BR EIDRM .
454 セマフォ集合がシステムから削除された: このとき
455 .BR semop ()
456 は失敗し
457 .I errno
458
459 .B EIDRM
460 が設定される。
461 .IP \(bu
462 .\"O The calling process catches a signal:
463 .\"O the value of
464 .\"O .I semncnt
465 .\"O is decremented and
466 .\"O .BR semop ()
467 .\"O fails, with
468 .\"O .I errno
469 .\"O set to
470 .\"O .BR EINTR .
471 呼び出したプロセスがシグナルを捕獲した: このとき
472 .I semncnt
473 が 1 減算され、
474 .BR semop ()
475 は失敗し
476 .I errno
477
478 .B EINTR
479 が設定される。
480 .IP \(bu
481 .\"O The time limit specified by
482 .\"O .I timeout
483 .\"O in a
484 .\"O .BR semtimedop ()
485 .\"O call expires: the system call fails, with
486 .\"O .I errno
487 .\"O set to
488 .\"O .BR EAGAIN .
489 .\" motoki: the system call は semtimedop () のこと?
490 .BR semtimedop ()
491
492 .I timeout
493 で指定された制限時間が経過した: このとき
494 .BR semtimedop ()
495 は失敗し、
496 .I errno
497
498 .B EAGAIN
499 が設定される。
500 .PP
501 .\"O On successful completion, the
502 .\"O .I sempid
503 .\"O value for each semaphore specified in the array pointed to by
504 .\"O .I sops
505 .\"O is set to the process ID of the calling process.
506 操作が成功した場合、
507 .I sops
508 が指す配列によって操作対象となった各セマフォの
509 .I sempid
510 メンバーには呼び出したプロセスのプロセス ID が設定される。
511 .\"O In addition, the
512 .\"O .I sem_otime
513 .\"O .\" and
514 .\"O .\" .I sem_ctime
515 .\"O is set to the current time.
516 さらに
517 .I sem_otime
518 .\" と
519 .\" .I sem_ctime
520 に現在時刻が設定される。
521 .PP
522 .\"O The function
523 .\"O .BR semtimedop ()
524 .\"O behaves identically to
525 .\"O .BR semop ()
526 .\"O except that in those cases were the calling process would sleep,
527 .\"O the duration of that sleep is limited by the amount of elapsed
528 .\"O time specified by the
529 .\"O .I timespec
530 .\"O structure whose address is passed in the
531 .\"O .I timeout
532 .\"O argument.
533 .BR semtimedop ()
534 関数の振る舞いは
535 .BR semop ()
536 と全く同じだが、
537 呼び出し元プロセスが停止する場合、停止期間の上限が
538 .I timeout
539 引き数の指す
540 .I timespec
541 構造体で指定された時間となる点だけが異なる。
542 .\"O If the specified time limit has been reached,
543 .\"O .BR semtimedop ()
544 .\"O fails with
545 .\"O .I errno
546 .\"O set to
547 .\"O .B EAGAIN
548 .\"O (and none of the operations in
549 .\"O .I sops
550 .\"O is performed).
551 指定した制限時間に達した場合は、
552 .BR semtimedop ()
553 は失敗し、
554 .I errno
555
556 .B EAGAIN
557 が設定される
558 (このとき
559 .I sops
560 の操作は実行されない)。
561 .\"O If the
562 .\"O .I timeout
563 .\"O argument is NULL,
564 .\"O then
565 .\"O .BR semtimedop ()
566 .\"O behaves exactly like
567 .\"O .BR semop ().
568 .I timeout
569 引き数が NULL の場合、
570 .BR semtimedop ()
571 関数の振る舞いは
572 .BR semop ()
573 関数と全く同じになる。
574 .\"O .SH "RETURN VALUE"
575 .SH 返り値
576 .\"O If successful
577 .\"O .BR semop ()
578 .\"O and
579 .\"O .BR semtimedop ()
580 .\"O return 0;
581 .\"O otherwise they return \-1
582 .\"O with
583 .\"O .I errno
584 .\"O indicating the error.
585 成功した場合、
586 .BR semop ()
587
588 .BR semtimedop ()
589 は 0 を返す。そうでなければ \-1 を返し、
590 エラーを示す
591 .I errno
592 を設定する。
593 .\"O .SH ERRORS
594 .SH エラー
595 .\"O On failure,
596 .\"O .I errno
597 .\"O is set to one of the following:
598 失敗した場合、
599 .I errno
600 に以下のどれかが設定される:
601 .TP
602 .B E2BIG
603 .\"O The argument
604 .\"O .I nsops
605 .\"O is greater than
606 .\"O .BR SEMOPM ,
607 .\"O the maximum number of operations allowed per system
608 .\"O call.
609 .I nsops
610 引き数が
611 .B SEMOPM
612 より大きい。
613 .B SEMOPM
614 は一回のシステムコールで許される操作の最大個数である。
615 .TP
616 .B EACCES
617 .\"O The calling process does not have the permissions required
618 .\"O to perform the specified semaphore operations,
619 .\"O and does not have the
620 .\"O .B CAP_IPC_OWNER
621 .\"O capability.
622 呼び出し元プロセスには指定されたセマフォ操作を行うのに
623 必要なアクセス許可がなく、
624 .B CAP_IPC_OWNER
625 ケーパビリティもない。
626 .TP
627 .B EAGAIN
628 .\"O An operation could not proceed immediately and either
629 .\"O .B IPC_NOWAIT
630 .\"O was specified in
631 .\"O .I sem_flg
632 .\"O or the time limit specified in
633 .\"O .I timeout
634 .\"O expired.
635 操作を直ちに処理することができず、かつ
636 .I sem_flg
637
638 .B IPC_NOWAIT
639 が指定されているか
640 .I timeout
641 で指定された制限時間が経過した。
642 .TP
643 .B EFAULT
644 .\"O An address specified in either the
645 .\"O .I sops
646 .\"O or the
647 .\"O .I timeout
648 .\"O arguments isn't accessible.
649 引き数
650 .I sops
651
652 .I timeout
653 が指しているアドレスにアクセスできない。
654 .TP
655 .B EFBIG
656 .\"O For some operation the value of
657 .\"O .I sem_num
658 .\"O is less than 0 or greater than or equal to the number
659 .\"O of semaphores in the set.
660 ある操作で、
661 .I sem_num
662 の値が 0 未満か、集合内のセマフォの数以上である。
663 .TP
664 .B EIDRM
665 .\"O The semaphore set was removed.
666 セマフォ集合が削除された。
667 .TP
668 .B EINTR
669 .\"O While blocked in this system call, the process caught a signal; see
670 .\"O .BR signal (7).
671 このシステムコールで停止している時にプロセスがシグナルを捕獲した。
672 .BR single (7)
673 参照。
674 .TP
675 .B EINVAL
676 .\"O The semaphore set doesn't exist, or
677 .\"O .I semid
678 .\"O is less than zero, or
679 .\"O .I nsops
680 .\"O has a nonpositive value.
681 セマフォ集合が存在しないか、
682 .I semid
683 が 0 未満であるか、
684 .I nsops
685 が正の数でない。
686 .TP
687 .B ENOMEM
688 .\"O The
689 .\"O .I sem_flg
690 .\"O of some operation specified
691 .\"O .B SEM_UNDO
692 .\"O and the system does not have enough memory to allocate the undo
693 .\"O structure.
694 ある操作で
695 .I sem_flg
696
697 .B SEM_UNDO
698 が指定されたが、システムにアンドゥ構造体に割り当てる十分なメモリがない。
699 .TP
700 .B ERANGE
701 .\"O For some operation
702 .\"O .I sem_op+semval
703 .\"O is greater than
704 .\"O .BR SEMVMX ,
705 .\"O the implementation dependent maximum value for
706 .\"O .IR semval .
707 ある操作で
708 .I sem_op+semval
709
710 .B SEMVMX
711 より大きい。
712 .B SEMVMX
713
714 .I semval
715 の最大値で、その値は実装依存である。
716 .\"O .SH VERSIONS
717 .SH バージョン
718 .\"O .BR semtimedop ()
719 .\"O first appeared in Linux 2.5.52,
720 .\"O and was subsequently backported into kernel 2.4.22.
721 .BR semtimedop ()
722 は Linux 2.5.52 で初めて登場し、
723 それからカーネル 2.4.22 にも移植された。
724 .\"O Glibc support for
725 .\"O .BR semtimedop ()
726 .\"O first appeared in version 2.3.3.
727 .BR semtimedop ()
728 の glibc でのサポートはバージョン 2.3.3 で初めて登場した。
729 .\"O .SH "CONFORMING TO"
730 .SH 準拠
731 SVr4, POSIX.1-2001.
732 .\"O .\" SVr4 documents additional error conditions EINVAL, EFBIG, ENOSPC.
733 .\" SVr4 には、追加で EINVAL, EFBIG, ENOSPC のエラー状態についての
734 .\" 記述がある。
735 .\"O .SH NOTES
736 .SH 注意
737 .\"O The
738 .\"O .I sem_undo
739 .\"O structures of a process aren't inherited by the child produced by
740 .\"O .BR fork (2),
741 .\"O but they are inherited across an
742 .\"O .BR execve (2)
743 .\"O system call.
744 あるプロセスの
745 .I sem_undo
746 構造体は
747 .BR fork (2)
748 で生成された子プロセスには継承されないが、
749 .BR execve (2)
750 システムコールの場合は継承される。
751 .PP
752 .\"O .BR semop ()
753 .\"O is never automatically restarted after being interrupted by a signal handler,
754 .\"O regardless of the setting of the
755 .\"O .B SA_RESTART
756 .\"O flag when establishing a signal handler.
757 .BR semop ()
758 はシグナルハンドラによって中断された後に、
759 決して自動的に再開することはない。
760 たとえシグナルハンドラの設定時に
761 .B SA_RESTART
762 フラグがセットされていても再開することはない
763 .PP
764 .\"O .I semadj
765 .\"O is a per-process integer which is simply the (negative) count
766 .\"O of all semaphore operations performed specifying the
767 .\"O .B SEM_UNDO
768 .\"O flag.
769 .I semadj
770 はプロセスごとの整数で、
771 .B SEM_UNDO
772 フラグを設定して実行された全てのセマフォ操作の(負数の)カウンタである。
773 .\"O When a semaphore's value is directly set using the
774 .\"O .B SETVAL
775 .\"O or
776 .\"O .B SETALL
777 .\"O request to
778 .\"O .BR semctl (2),
779 .\"O the corresponding
780 .\"O .I semadj
781 .\"O values in all processes are cleared.
782 .BR semctl (2)
783
784 .B SETVAL
785 または
786 .B SETALL
787 を指定し、セマフォの値が
788 直接設定された場合には、全てのプロセスにおいて対応する
789 .I semadj
790 の値がクリアされる。
791 .PP
792 .\"O The \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, and \fIsemnct\fP values
793 .\"O for a semaphore can all be retrieved using appropriate
794 .\"O .BR semctl (2)
795 .\"O calls.
796 あるセマフォの \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, \fIsemnct\fP
797 の値はいずれも、適切な操作を指定して
798 .BR semctl (2)
799 を呼び出すことで取得できる。
800 .PP
801 .\"O The following limits on semaphore set resources affect the
802 .\"O .BR semop ()
803 .\"O call:
804 セマフォ集合のリソースに関する制限のうち、
805 .BR semop ()
806 に影響を及ぼすものを以下に挙げる:
807 .TP
808 .B SEMOPM
809 .\"O Maximum number of operations allowed for one
810 .\"O .BR semop ()
811 .\"O call (32)
812 .\"O (on Linux, this limit can be read and modified via the third field of
813 .\"O .IR /proc/sys/kernel/sem ).
814 .\"O .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
815 一回の
816 .BR semop ()
817 で許される操作の最大数 (32)。
818 (Linux では、この制限値は
819 .I /proc/sys/kernel/sem
820 の第3フィールドに対応し、読み出しも変更もできる)。
821 .\" この /proc ファイルは Linux 2.2 以前では利用できない -- MTK
822 .TP
823 .B SEMVMX
824 .\"O Maximum allowable value for
825 .\"O .IR semval :
826 .\"O implementation dependent (32767).
827 .I semval
828 が取り得る最大値: 実装依存 (32767)。
829 .PP
830 .\"O The implementation has no intrinsic limits for
831 .\"O the adjust on exit maximum value
832 .\"O .RB ( SEMAEM ),
833 .\"O the system wide maximum number of undo structures
834 .\"O .RB ( SEMMNU )
835 .\"O and the per-process maximum number of undo entries system parameters.
836 以下の値に関しては実装依存の制限はない。
837 終了時の調整 (adjust on exit) の最大値
838 .RB ( SEMAEM )、
839 システム全体のアンドゥ構造体の最大数
840 .RB ( SEMMNU )、
841 プロセスあたりのアンドゥ構造体の最大数。
842 .\"O .SH BUGS
843 .SH バグ
844 .\"O When a process terminates, its set of associated
845 .\"O .I semadj
846 .\"O structures is used to undo the effect of all of the
847 .\"O semaphore operations it performed with the
848 .\"O .B SEM_UNDO
849 .\"O flag.
850 プロセスが終了する際、プロセスに対応する
851 .I semadj
852 の集合を使って、
853 .B SEM_UNDO
854 フラグ付きで実行された全てのセマフォ操作の影響を取り消す。
855 .\"O This raises a difficulty: if one (or more) of these semaphore adjustments
856 .\"O would result in an attempt to decrease a semaphore's value below zero,
857 .\"O what should an implementation do?
858 これによりある問題が発生する: これらのセマフォの調整を行っていると、
859 中にはセマフォの値が 0 未満の値にしようとする場合が出てくる。
860 このような場合、どのように実装するべきか?
861 .\"O One possible approach would be to block until all the semaphore
862 .\"O adjustments could be performed.
863 .\"O This is however undesirable since it could force process termination to
864 .\"O block for arbitrarily long periods.
865 ひとつの考えられる手法は、全てのセマフォ調整が実行されるまで
866 停止することである。しかし、この方法ではプロセスの終了が
867 長時間にわたって停止されることがあるので望ましくない。
868 しかもどれくらい長時間になるかは分からない。
869 .\"O Another possibility is that such semaphore adjustments could be ignored
870 .\"O altogether (somewhat analogously to failing when
871 .\"O .B IPC_NOWAIT
872 .\"O is specified for a semaphore operation).
873 別の選択肢として、このようなセマフォ調整を完全に無視してしまう方法がある
874 (これはセマフォ操作として
875 .B IPC_NOWAIT
876 が指定するのと少し似ている)。
877 .\"O Linux adopts a third approach: decreasing the semaphore value
878 .\"O as far as possible (i.e., to zero) and allowing process
879 .\"O termination to proceed immediately.
880 Linux は第三の手法を採用している: セマフォの値を出来るだけ (つまり
881 0 まで) 減少させて、プロセスの終了を直ちに続行できるようにしている。
882
883 .\"O In kernels 2.6.x, x <= 10, there is a bug that in some circumstances
884 .\"O prevents a process that is waiting for a semaphore value to become
885 .\"O zero from being woken up when the value does actually become zero.
886 .\"O This bug is fixed in kernel 2.6.11.
887 .\"O .\" The bug report:
888 .\"O .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
889 .\"O .\" the fix:
890 .\"O .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
891 カーネル 2.6.x (x <= 10) には、ある状況においてセマフォ値が 0 になるのを
892 待っているプロセスが、セマフォ値が実際に 0 になったときに起床 (wake up)
893 されない、というバグがある。このバグはカーネル 2.6.11 で修正されている。
894 .\" バグレポート:
895 .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
896 .\" 修正:
897 .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
898 .\"O .SH EXAMPLE
899 .SH 例
900 .\"O The following code segment uses
901 .\"O .BR semop ()
902 .\"O to atomically wait for the value of semaphore 0 to become zero,
903 .\"O and then increment the semaphore value by one.
904 以下の部分的なコードは、
905 セマフォ 0 の値が 0 になるのを待ってから、
906 セマフォの値を 1 加算する処理を、
907 .BR semop ()
908 を使ってアトミック (atomically) に行う。
909 .nf
910
911     struct sembuf sops[2];
912     int semid;
913
914     /* Code to set \fIsemid\fP omitted */
915
916     sops[0].sem_num = 0;        /* Operate on semaphore 0 */
917     sops[0].sem_op = 0;         /* Wait for value to equal 0 */
918     sops[0].sem_flg = 0;
919
920     sops[1].sem_num = 0;        /* Operate on semaphore 0 */
921     sops[1].sem_op = 1;         /* Increment value by one */
922     sops[1].sem_flg = 0;
923
924     if (semop(semid, sops, 2) == \-1) {
925         perror("semop");
926         exit(EXIT_FAILURE);
927     }
928 .fi
929 .\"O .SH "SEE ALSO"
930 .SH 関連項目
931 .BR semctl (2),
932 .BR semget (2),
933 .BR sigaction (2),
934 .BR capabilities (7),
935 .BR sem_overview (7),
936 .BR svipc (7),
937 .BR time (7)