OSDN Git Service

長音記号の修正を release に反映
[linuxjm/LDP_man-pages.git] / release / man2 / semop.2
index 7b82739..d8ae7a6 100644 (file)
 .\" This file was generated with po4a. Translate the source file.
 .\"
 .\"*******************************************************************
-.TH SEMOP 2 2012\-08\-27 Linux "Linux Programmer's Manual"
+.\"
+.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
+.\"         all rights reserved.
+.\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
+.\" Updated 2003-02-09, Kentaro Shirakata <argrath@ub32.org>
+.\" Updated 2003-09-12, Kentaro Shirakata <argrath@ub32.org>
+.\" Updated 2005-03-01, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
+.\" Updated 2005-04-17, Akihiro MOTOKI
+.\" Updated 2005-09-06, Akihiro MOTOKI
+.\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
+.\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2013-05-06, Akihiro MOTOKI <amotoki@gmail.com>
+.\"
+.TH SEMOP 2 2014\-12\-31 Linux "Linux Programmer's Manual"
 .SH 名前
-semop, semtimedop \- セマフォの操作
+semop, semtimedop \- System V セマフォの操作
 .SH 書式
 .nf
 \fB#include <sys/types.h>\fP
 \fB#include <sys/ipc.h>\fP
 \fB#include <sys/sem.h>\fP
 .sp
-\fBint semop(int \fP\fIsemid\fP\fB, struct sembuf *\fP\fIsops\fP\fB, unsigned \fP\fInsops\fP\fB);\fP
+\fBint semop(int \fP\fIsemid\fP\fB, struct sembuf *\fP\fIsops\fP\fB, size_t \fP\fInsops\fP\fB);\fP
 .sp
-\fBint semtimedop(int \fP\fIsemid\fP\fB, struct sembuf *\fP\fIsops\fP\fB, unsigned \fP\fInsops\fP\fB,\fP
-\fB               struct timespec *\fP\fItimeout\fP\fB);\fP
+\fBint semtimedop(int \fP\fIsemid\fP\fB, struct sembuf *\fP\fIsops\fP\fB, size_t \fP\fInsops\fP\fB,\fP
+\fB               const struct timespec *\fP\fItimeout\fP\fB);\fP
 .fi
 .sp
 .in -4n
@@ -58,19 +71,19 @@ glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参
 .sp
 \fBsemtimedop\fP(): _GNU_SOURCE
 .SH 説明
-セマフォ集合 (semaphore set) のメンバーの各セマフォは 以下の関連情報を持っている:
+System\ V セマフォ集合 (semaphore set) のメンバーの各セマフォは 以下の関連情報を持っている:
 .sp
 .in +4n
 .nf
-unsigned short  semval;   /* semaphore value */
-unsigned short  semzcnt;  /* # waiting for zero */
-unsigned short  semncnt;  /* # waiting for increase */
-pid_t           sempid;   /* ID of process that did last op */
+unsigned short  semval;   /* セマフォ値 */
+unsigned short  semzcnt;  /* ゼロを待つプロセス数 */
+unsigned short  semncnt;  /* 増加を待つプロセス数 */
+pid_t           sempid;   /* 最後に操作を行なったプロセスの ID */
 .sp
 .in -4n
 .fi
 \fBsemop\fP()  は \fIsemid\fP で指定されたセマフォ集合の選択されたセマフォに対して操作を行う。 \fIsops\fP は \fInsops\fP
-個の要素の配列を指し、配列の各要素は個々のセマフォに 対する操作を示す。その型は \fIstruct sembuf\fP で、次のメンバを持つ:
+個の要素の配列を指し、配列の各要素は個々のセマフォに対する操作を示す構造体である。その型は \fIstruct sembuf\fP で、次のメンバを持つ:
 .sp
 .in +4n
 .nf
@@ -90,72 +103,56 @@ short          sem_flg;  /* 操作フラグ */
 それぞれの操作はセマフォ集合の \fIsem_num\fP番目 のセマフォに対して実行される。セマフォ集合の最初のセマフォには 番号 0 が振られる。
 そして操作は三種類あり、 \fIsem_op\fP の値で区別される。
 .PP
-If \fIsem_op\fP is a positive integer, the operation adds this value to the
-semaphore value (\fIsemval\fP).  Furthermore, if \fBSEM_UNDO\fP is specified for
-this operation, the system updates the undo count (\fIsemadj\fP)  for this
-semaphore.  This operation can always proceed\(emit never forces a thread to
-wait.  The calling process must have alter permission on the semaphore set.
+\fIsem_op\fP が正の整数の場合、その値をセマフォの値 (\fIsemval\fP) に加算する。 さらに、この操作で \fBSEM_UNDO\fP
+が指定されていた場合は、 システムはこのセマフォのの調整値 (\fIsemadj\fP) から値 \fIsem_op\fP を減算する。 この操作は必ず実行でき、
+スレッドの停止は起こらない。 呼び出し元プロセスは対象のセマフォ集合を変更する許可がなければならない。
 .PP
-If \fIsem_op\fP is zero, the process must have read permission on the semaphore
-set.  This is a "wait\-for\-zero" operation: if \fIsemval\fP is zero, the
-operation can immediately proceed.  Otherwise, if \fBIPC_NOWAIT\fP is specified
-in \fIsem_flg\fP, \fBsemop\fP()  fails with \fIerrno\fP set to \fBEAGAIN\fP (and none of
-the operations in \fIsops\fP is performed).  Otherwise \fIsemzcnt\fP (the count of
-threads waiting until this semaphore's value becomes zero)  is incremented
-by one and the thread sleeps until one of the following occurs:
+\fIsem_op\fP が 0 の場合、「ゼロまで待つ」操作である。この場合、プロセスは そのセマフォ集合に対する読み込み許可がなければならない。
+\fIsemval\fP が 0 ならば、操作は直ちに行われる。 \fIsemval\fP が 0 でない場合、 \fIsem_flg\fP に
+\fBIPC_NOWAIT\fP が指定されていれば、 \fBsemop\fP()  は失敗し、 \fBerrno\fP に \fBEAGAIN\fP が設定される (このとき
+\fIsops\fP に対する操作は全く実行されない)。 \fIsem_flg\fP に \fBIPC_NOWAIT\fP が指定されていない場合、 \fIsemzcnt\fP
+(セマフォ値が 0 になるのを待っているスレッドの数) を 1 増加させて、 以下のいずれかが起こるまでスレッドを停止 (sleep) する。
 .IP \(bu 3
 \fIsemval\fP が 0 になった: このとき \fIsemzcnt\fP の値は 1 減算される。
 .IP \(bu
 セマフォ集合が削除された: このとき \fBsemop\fP()  は失敗し、 \fIerrno\fP に \fBEIDRM\fP が設定される。
 .IP \(bu
-The calling thread catches a signal: the value of \fIsemzcnt\fP is decremented
-and \fBsemop\fP()  fails, with \fIerrno\fP set to \fBEINTR\fP.
-.IP \(bu
-\fBsemtimedop\fP()  の \fItimeout\fP で指定された制限時間が経過した: このとき \fBsemtimedop\fP()  は失敗し、
-\fIerrno\fP に \fBEAGAIN\fP が設定される。
+呼び出し元スレッドがシグナルを捕獲した: このとき \fIsemzcnt\fP の値は 1 減算され、 \fBsemop\fP()  は失敗し \fIerrno\fP に
+\fBEINTR\fP が設定される。
 .PP
-If \fIsem_op\fP is less than zero, the process must have alter permission on
-the semaphore set.  If \fIsemval\fP is greater than or equal to the absolute
-value of \fIsem_op\fP, the operation can proceed immediately: the absolute
-value of \fIsem_op\fP is subtracted from \fIsemval\fP, and, if \fBSEM_UNDO\fP is
-specified for this operation, the system updates the undo count (\fIsemadj\fP)
-for this semaphore.  If the absolute value of \fIsem_op\fP is greater than
-\fIsemval\fP, and \fBIPC_NOWAIT\fP is specified in \fIsem_flg\fP, \fBsemop\fP()  fails,
-with \fIerrno\fP set to \fBEAGAIN\fP (and none of the operations in \fIsops\fP is
-performed).  Otherwise \fIsemncnt\fP (the counter of threads waiting for this
-semaphore's value to increase)  is incremented by one and the thread sleeps
-until one of the following occurs:
+\fIsem_op\fP が 0 未満の場合、プロセスにはそのセマフォ集合を変更する許可がなければ ならない。 \fIsemval\fP が \fIsem_op\fP
+の絶対値以上の場合は、操作は直ちに実行される: \fIsemval\fP から \fIsem_op\fP の絶対値を減算し、さらに、この操作に
+\fBSEM_UNDO\fP が指定されている場合は、このセマフォの調整値 (\fIsemadj\fP) に \fIsem_op\fP の絶対値を加算する。
+\fIsemval\fP が \fIsem_op\fP の絶対値より小さく、 \fIsem_flg\fP に \fBIPC_NOWAIT\fP が指定された場合は、
+\fBsemop\fP()  は失敗し、 \fIerrno\fP に \fBEAGAIN\fP が設定される (このとき \fIsops\fP の操作は全く実行されない)。
+\fIsemval\fP が \fIsem_op\fP の絶対値より小さく、 \fBIPC_WAIT\fP が指定されていない場合は、 \fIsemncnt\fP
+(このセマフォの値が増加するのを待っているスレッド数のカウンター)  を 1 増加させて、以下のいずれかが起こるまでスレッドを停止 (sleep)
+する。
 .IP \(bu 3
-\fIsemval\fP becomes greater than or equal to the absolute value of \fIsem_op\fP,
-at which time the value of \fIsemncnt\fP is decremented, the absolute value of
-\fIsem_op\fP is subtracted from \fIsemval\fP and, if \fBSEM_UNDO\fP is specified for
-this operation, the system updates the undo count (\fIsemadj\fP)  for this
-semaphore.
+\fIsemval\fP が \fIsem_op\fP の絶対値以上になった。この時点で、操作は上述の通り実行される。
 .IP \(bu
 セマフォ集合がシステムから削除された: このとき \fBsemop\fP()  は失敗し \fIerrno\fP に \fBEIDRM\fP が設定される。
 .IP \(bu
-The calling thread catches a signal: the value of \fIsemncnt\fP is decremented
-and \fBsemop\fP()  fails, with \fIerrno\fP set to \fBEINTR\fP.
-.IP \(bu
-\fBsemtimedop\fP()  の \fItimeout\fP で指定された制限時間が経過した: このとき \fBsemtimedop\fP()  は失敗し、
-\fIerrno\fP に \fBEAGAIN\fP が設定される。
+呼び出したスレッドがシグナルを捕獲した: このとき \fIsemncnt\fP が 1 減算され、 \fBsemop\fP()  は失敗し \fIerrno\fP に
+\fBEINTR\fP が設定される。
 .PP
 .\" and
 .\" .I sem_ctime
-On successful completion, the \fIsempid\fP value for each semaphore specified
-in the array pointed to by \fIsops\fP is set to the caller's process ID.  In
-addition, the \fIsem_otime\fP is set to the current time.
-.PP
-\fBsemtimedop\fP()  behaves identically to \fBsemop\fP()  except that in those
-cases where the calling thread would sleep, the duration of that sleep is
-limited by the amount of elapsed time specified by the \fItimespec\fP structure
-whose address is passed in the \fItimeout\fP argument.  (This sleep interval
-will be rounded up to the system clock granularity, and kernel scheduling
-delays mean that the interval may overrun by a small amount.)  If the
-specified time limit has been reached, \fBsemtimedop\fP()  fails with \fIerrno\fP
-set to \fBEAGAIN\fP (and none of the operations in \fIsops\fP is performed).  If
-the \fItimeout\fP argument is NULL, then \fBsemtimedop\fP()  behaves exactly like
-\fBsemop\fP().
+操作が成功した場合、 \fIsops\fP が指す配列によって操作対象となった各セマフォの \fIsempid\fP メンバーには呼び出し元のプロセス ID
+が設定される。さらに \fIsem_otime\fP に現在時刻が設定される。
+.SS semtimedop()
+\fBsemtimedop\fP() 関数の振る舞いは \fBsemop\fP() と全く同じだが、呼び出し元
+スレッドが停止する場合、停止期間の上限が \fItimeout\fP 引き数の指す
+\fItimespec\fP 構造体で指定された時間となる点だけが異なる (この停止期間は
+システムクロックの粒度に切り上げられ、カーネルのスケジューリング遅延に
+より、この停止期間は少しだけ長くなる可能性がある)。
+指定した制限時間に達した場合は、 \fBsemtimedop\fP() は失敗し、 \fIerrno\fP に
+\fBEAGAIN\fP が設定される (このとき \fIsops\fP の操作は実行されない)。
+\fItimeout\fP 引き数が NULL の場合、 \fBsemtimedop\fP() 関数の振る舞いは
+\fBsemop\fP() 関数と全く同じになる。
+
+\fBsemtimeop\fP() がシグナルにより割り込まれた場合、呼び出しはエラー \fBEINTR\fP で失敗し、 \fItimeout\fP
+の内容は変更されないままとなる点に注意すること。
 .SH 返り値
 成功した場合、 \fBsemop\fP()  と \fBsemtimedop\fP()  は 0 を返す。そうでなければ \-1 を返し、 エラーを示す
 \fIerrno\fP を設定する。
@@ -182,14 +179,13 @@ the \fItimeout\fP argument is NULL, then \fBsemtimedop\fP()  behaves exactly lik
 セマフォ集合が削除された。
 .TP 
 \fBEINTR\fP
-While blocked in this system call, the thread caught a signal; see
-\fBsignal\fP(7).
+このシステムコールで停止している時にスレッドがシグナルを捕獲した。 \fBsingle\fP(7) 参照。
 .TP 
 \fBEINVAL\fP
 セマフォ集合が存在しないか、 \fIsemid\fP が 0 未満であるか、 \fInsops\fP が正の数でない。
 .TP 
 \fBENOMEM\fP
-ある操作で \fIsem_flg\fP に \fBSEM_UNDO\fP が指定されたが、システムにアンドゥ構造体に割り当てる十分なメモリがない。
\81\82ã\82\8bæ\93\8dä½\9cã\81§ \fIsem_flg\fP ã\81« \fBSEM_UNDO\fP ã\81\8cæ\8c\87å®\9aã\81\95ã\82\8cã\81\9fã\81\8cã\80\81ã\82·ã\82¹ã\83\86ã\83 ã\81«ã\82¢ã\83³ã\83\89ã\82¥æ§\8bé\80 ä½\93ã\81«å\89²ã\82\8aå½\93ã\81¦ã\82\8bå\8d\81å\88\86ã\81ªã\83¡ã\83¢ã\83ªã\83¼ã\81\8cã\81ªã\81\84ã\80\82
 .TP 
 \fBERANGE\fP
 ある操作で \fIsem_op+semval\fP が \fBSEMVMX\fP より大きい。 \fBSEMVMX\fP は \fIsemval\fP
@@ -203,25 +199,27 @@ SVr4, POSIX.1\-2001.
 .SH 注意
 .\" Like Linux, the FreeBSD man pages still document
 .\" the inclusion of these header files.
-The inclusion of \fI<sys/types.h>\fP and \fI<sys/ipc.h>\fP isn't
-required on Linux or by any version of POSIX.  However, some old
-implementations required the inclusion of these header files, and the SVID
-also documented their inclusion.  Applications intended to be portable to
-such old systems may need to include these header files.
+Linux や POSIX の全てのバージョンでは、 \fI<sys/types.h>\fP と \fI<sys/ipc.h>\fP
+のインクルードは必要ない。しかしながら、いくつかの古い実装ではこれらのヘッダーファイルのインクルードが必要であり、 SVID
+でもこれらのインクルードをするように記載されている。このような古いシステムへの移植性を意図したアプリケーションではこれらのファイルをインクルードする必要があるかもしれない。
 
 あるプロセスの \fIsem_undo\fP 構造体は \fBfork\fP(2)  で生成された子プロセスには継承されないが、 \fBexecve\fP(2)
 システムコールの場合は継承される。
 .PP
-\fBsemop\fP()  ã\81¯ã\82·ã\82°ã\83\8aã\83«ã\83\8fã\83³ã\83\89ã\83©ã\81«ã\82\88ã\81£ã\81¦ä¸­æ\96­ã\81\95ã\82\8cã\81\9få¾\8cã\81«ã\80\81 æ±ºã\81\97ã\81¦è\87ªå\8b\95ç\9a\84ã\81«å\86\8dé\96\8bã\81\99ã\82\8bã\81\93ã\81¨ã\81¯ã\81ªã\81\84ã\80\82 ã\81\9fã\81¨ã\81\88ã\82·ã\82°ã\83\8aã\83«ã\83\8fã\83³ã\83\89ã\83©の設定時に
+\fBsemop\fP()  ã\81¯ã\82·ã\82°ã\83\8aã\83«ã\83\8fã\83³ã\83\89ã\83©ã\83¼ã\81«ã\82\88ã\81£ã\81¦ä¸­æ\96­ã\81\95ã\82\8cã\81\9få¾\8cã\81«ã\80\81 æ±ºã\81\97ã\81¦è\87ªå\8b\95ç\9a\84ã\81«å\86\8dé\96\8bã\81\99ã\82\8bã\81\93ã\81¨ã\81¯ã\81ªã\81\84ã\80\82 ã\81\9fã\81¨ã\81\88ã\82·ã\82°ã\83\8aã\83«ã\83\8fã\83³ã\83\89ã\83©ã\83¼の設定時に
 \fBSA_RESTART\fP フラグがセットされていても再開することはない
-.PP
-\fIsemadj\fP はプロセスごとの整数で、 \fBSEM_UNDO\fP フラグを設定して実行された全てのセマフォ操作の(負数の)カウンタである。
-\fBsemctl\fP(2)  に \fBSETVAL\fP または \fBSETALL\fP を指定し、セマフォの値が
-直接設定された場合には、全てのプロセスにおいて対応する \fIsemadj\fP の値がクリアされる。
-.PP
+
+セマフォの調整値 (\fIsemadj\fP) は、プロセス毎のセマフォ毎の整数で、 \fBSEM_UNDO\fP
+フラグを指定して行われた、セマフォに対するすべての操作の合計値を反転したものである。 各プロセスは \fIsemadj\fP の値のリストを保持する \(em
+リストのそれぞれの値は \fBSEM_UNDO\fP を使って操作が行われた個々のセマフォに対応する。 プロセスが終了する際、 セマフォ毎の
+\fIsemadj\fP の各々の値が対応するセマフォに加算される。 これにより、そのプロセスがそのセマフォに対して行った操作の影響が取り消される
+(ただし、下記の「バグ」を参照)。 \fBsemctl\fP(2) の \fBSETVAL\fP や \fBSETALL\fP を使ってセマフォの値が直接設定された場合、
+すべてのプロセスの対応する \fIsemadj\fP の値がクリアされる。 \fBclone\fP(2) の \fBCLONE_SYSVSEM\fP フラグを使うと、
+複数のプロセスがひとつの \fIsemadj\fP リストを共有できる。 詳細は \fBclone\fP(2) を参照。
+
 あるセマフォの \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, \fIsemnct\fP の値はいずれも、適切な操作を指定して
 \fBsemctl\fP(2)  を呼び出すことで取得できる。
-.PP
+.SS セマフォの上限
 セマフォ集合のリソースに関する制限のうち、 \fBsemop\fP()  に影響を及ぼすものを以下に挙げる:
 .TP 
 \fBSEMOPM\fP
@@ -247,10 +245,8 @@ such old systems may need to include these header files.
 .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
 .\" the fix:
 .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
-In kernels 2.6.x, x <= 10, there is a bug that in some circumstances
-prevents a thread that is waiting for a semaphore value to become zero from
-being woken up when the value does actually become zero.  This bug is fixed
-in kernel 2.6.11.
+カーネル 2.6.x (x <= 10) には、ある状況においてセマフォ値が 0 になるのを 待っているスレッドが、セマフォ値が実際に 0
+になったときに起床 (wake up)  されない、というバグがある。このバグはカーネル 2.6.11 で修正されている。
 .SH 例
 以下の部分的なコードは、 セマフォ 0 の値が 0 になるのを待ってから、 セマフォの値を 1 加算する処理を、 \fBsemop\fP()
 を使ってアトミック (atomically) に行う。
@@ -278,6 +274,6 @@ in kernel 2.6.11.
 \fBclone\fP(2), \fBsemctl\fP(2), \fBsemget\fP(2), \fBsigaction\fP(2),
 \fBcapabilities\fP(7), \fBsem_overview\fP(7), \fBsvipc\fP(7), \fBtime\fP(7)
 .SH この文書について
-この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.78 の一部
 である。プロジェクトの説明とバグ報告に関する情報は
 http://www.kernel.org/doc/man\-pages/ に書かれている。