1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" Modified Tue Oct 22 17:53:56 1996 by Eric S. Raymond <esr@thyrsus.com>
25 .\" Modified Fri Jun 19 10:59:15 1998 by Andries Brouwer <aeb@cwi.nl>
26 .\" Modified Sun Feb 18 01:59:29 2001 by Andries Brouwer <aeb@cwi.nl>
27 .\" Modified 20 Dec 2001, Michael Kerrisk <mtk.manpages@gmail.com>
28 .\" Modified 21 Dec 2001, aeb
29 .\" Modified 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
30 .\" Added notes on CAP_IPC_OWNER requirement
31 .\" Modified 17 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
32 .\" Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID
33 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
34 .\" Language and formatting clean-ups
35 .\" Rewrote semun text
36 .\" Added semid_ds and ipc_perm structure definitions
37 .\" 2005-08-02, mtk: Added IPC_INFO, SEM_INFO, SEM_STAT descriptions.
39 .\" Japanese Version Copyright (c) 1997,1998 HANATAKA Shinya
40 .\" all rights reserved.
41 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
42 .\" Modified 1998-09-10, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
43 .\" Updated & Modified 2001-06-03, Yuichi SATO <ysato@h4.dion.ne.jp>
44 .\" Updated & Modified 2002-01-02, Yuichi SATO
45 .\" Updated & Modified 2005-01-03, Yuichi SATO <ysato444@yahoo.co.jp>
46 .\" Updated & Modified 2005-10-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
48 .\"WORD: semaphore セマフォ
49 .\"WORD: semaphore set セマフォ集合
53 .\"WORD: superuser スーパー・ユーザ
54 .\"WORD: effective uid 実効ユーザ ID
60 .\"WORD: feature test macro 機能検査マクロ
62 .TH SEMCTL 2 2009-09-27 "Linux" "Linux Programmer's Manual"
65 .\"O semctl \- semaphore control operations
66 semctl \- セマフォの制御操作を行なう
70 .B #include <sys/types.h>
71 .B #include <sys/ipc.h>
72 .B #include <sys/sem.h>
74 .BI "int semctl(int " semid ", int " semnum ", int " cmd ", ...);"
79 .\"O performs the control operation specified by
81 .\"O on the semaphore set identified by
85 .\"O semaphore of that set.
86 .\"O (The semaphores in a set are numbered starting at 0.)
90 で指定されたセマフォ集合 (semaphore set)
96 (集合内のセマフォの番号は 0 から始まる)。
98 .\"O This function has three or four arguments, depending on
100 .\"O When there are four, the fourth has the type
101 .\"O .IR "union semun" .
102 .\"O The \fIcalling program\fP must define this union as follows:
105 の値に依存して、3 個または 4 個の引き数を持つ。
106 引き数が 4 個の場合、第 4 引き数の型は
110 この共用体 (union) を以下のように定義しなければならない。
115 .\"O int val; /* Value for SETVAL */
116 int val; /* SETVAL の値 */
117 .\"O struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */
118 struct semid_ds *buf; /* IPC_STAT, IPC_SET 用のバッファ */
119 .\"O unsigned short *array; /* Array for GETALL, SETALL */
120 unsigned short *array; /* GETALL, SETALL 用の配列 */
121 .\"O struct seminfo *__buf; /* Buffer for IPC_INFO
122 .\"O (Linux-specific) */
123 struct seminfo *__buf; /* IPC_INFO 用のバッファ
131 .\"O data structure is defined in \fI<sys/sem.h>\fP as follows:
133 データ構造体は \fI<sys/sem.h>\fP で以下のように定義されている:
138 .\"O struct ipc_perm sem_perm; /* Ownership and permissions */
139 struct ipc_perm sem_perm; /* 所有権と許可 */
140 .\"O time_t sem_otime; /* Last semop time */
141 time_t sem_otime; /* 最後の semop の時刻 */
142 .\"O time_t sem_ctime; /* Last change time */
143 time_t sem_ctime; /* 最後に変更が行われた時刻 */
144 .\"O unsigned short sem_nsems; /* No. of semaphores in set */
145 unsigned short sem_nsems; /* 集合内のセマフォの数 */
154 .\"O structure is defined in \fI<sys/ipc.h>\fP as follows
155 .\"O (the highlighted fields are settable using
158 構造体は \fI<sys/ipc.h>\fP で以下のように定義されている
166 .\"O key_t __key; /* Key supplied to semget(2) */
167 .\"O uid_t \fBuid\fP; /* Effective UID of owner */
168 .\"O gid_t \fBgid\fP; /* Effective GID of owner */
169 .\"O uid_t cuid; /* Effective UID of creator */
170 .\"O gid_t cgid; /* Effective GID of creator */
171 key_t __key; /* semget(2) に与えられるキー */
172 uid_t \fBuid\fP; /* 所有者 (owner) の実効 UID */
173 gid_t \fBgid\fP; /* 所有者の実効 GID */
174 uid_t cuid; /* 作成者 (creator) の実効 UID */
175 gid_t cgid; /* 作成者の実効 GID */
176 .\"O unsigned short \fBmode\fP; /* Permissions */
177 unsigned short \fBmode\fP; /* 許可 */
178 .\"O unsigned short __seq; /* Sequence number */
179 unsigned short __seq; /* シーケンス番号 */
184 .\"O Valid values for
191 .\"O Copy information from the kernel data structure associated with
195 .\"O structure pointed to by
198 に関連づけられたカーネルデータ構造体の情報を
206 .\"O The calling process must have read permission on the semaphore set.
209 呼び出したプロセスはそのセマフォ集合に対する
213 .\"O Write the values of some members of the
215 .\"O structure pointed to by
217 .\"O to the kernel data structure associated with this semaphore set,
218 .\"O updating also its
224 このセマフォに関連づけられたカーネルデータ構造体に書き込み、
227 .\"O The following members of the structure are updated:
228 .\"O .IR sem_perm.uid ,
229 .\"O .IR sem_perm.gid ,
230 .\"O and (the least significant 9 bits of)
231 .\"O .IR sem_perm.mode .
237 .\"O The effective UID of the calling process must match the owner
238 .\"O .RI ( sem_perm.uid )
240 .\"O .RI ( sem_perm.cuid )
241 .\"O of the semaphore set, or the caller must be privileged.
242 呼び出したプロセスの実効 UID が所有者
245 .RI ( sem_perm.cuid )
246 と一致するか、呼び出した人が特権を持たなければならない。
254 .\"O Immediately remove the semaphore set,
255 .\"O awakening all processes blocked in
257 .\"O calls on the set (with an error return and
261 セマフォ集合をただちに削除し、その集合上の
263 コールでブロックされている全てのプロセスを目覚めさせる
269 .\"O The effective user ID of the calling process must
270 .\"O match the creator or owner of the semaphore set,
271 .\"O or the caller must be privileged.
276 そのセマフォ集合の作成者または所有者と一致するか、
277 呼び出した人が特権を持たなければならない。
281 .\"O .BR IPC_INFO " (Linux-specific)"
282 .BR IPC_INFO " (Linux 固有)"
283 .\"O Returns information about system-wide semaphore limits and
284 .\"O parameters in the structure pointed to by
286 システム全体でのセマフォの制限とパラメータに関する情報を、
289 .\"O This structure is of type
295 .\"O feature test macro is defined:
309 .\"O int semmap; /* Number of entries in semaphore
310 .\"O map; unused within kernel */
311 .\"O int semmni; /* Maximum number of semaphore sets */
312 .\"O int semmns; /* Maximum number of semaphores in all
313 .\"O semaphore sets */
314 .\"O int semmnu; /* System-wide maximum number of undo
315 .\"O structures; unused within kernel */
316 .\"O int semmsl; /* Maximum number of semaphores in a
318 .\"O int semopm; /* Maximum number of operations for
320 .\"O int semume; /* Maximum number of undo entries per
321 .\"O process; unused within kernel */
322 .\"O int semusz; /* Size of struct sem_undo */
323 .\"O int semvmx; /* Maximum semaphore value */
324 .\"O int semaem; /* Max. value that can be recorded for
325 .\"O semaphore adjustment (SEM_UNDO) */
326 int semmap; /* セマフォ・マップの最大エントリ数;
328 int semmni; /* セマフォ集合の最大数 */
329 int semmns; /* 全セマフォ集合中のセマフォの
331 int semmnu; /* アンドゥ構造体のシステム全体での
333 int semmsl; /* 一つのセマフォ集合の最大セマフォ数 */
334 int semopm; /* semop(2) に渡す操作の最大数 */
335 int semume; /* プロセスあたりのアンドゥ・エントリ
337 int semusz; /* 構造体 sem_undo のサイズ */
338 int semvmx; /* セマフォの最大値 */
339 int semaem; /* セマフォの調整 (semaphore adjustment;
340 SEM_UNDO) のために記録される最大値 */
351 .\"O settings can be changed via
352 .\"O .IR /proc/sys/kernel/sem ;
362 .I /proc/sys/kernel/sem
368 .\"O .BR SEM_INFO " (Linux-specific)"
369 .BR SEM_INFO " (Linux 固有)"
372 .\"O structure containing the same information as for
374 .\"O except that the following fields are returned with information
375 .\"O about system resources consumed by semaphores: the
377 .\"O field returns the number of semaphore sets that currently exist
378 .\"O on the system; and the
380 .\"O field returns the total number of semaphores in all semaphore sets
386 但し、以下のフィールドにはセマフォが消費しているシステム資源に
389 フィールドは現在システム上に存在するセマフォ集合の数を返す。
391 フィールドはシステム上の全てのセマフォ集合に含まれる
394 .\"O .BR SEM_STAT " (Linux-specific)"
395 .BR SEM_STAT " (Linux 固有)"
398 .\"O structure as for
406 .\"O argument is not a semaphore identifier, but instead an index into
407 .\"O the kernel's internal array that maintains information about
408 .\"O all semaphore sets on the system.
411 引き数は、セマフォ識別子ではなく、システム上の全てのセマフォ集合
412 に関する情報を管理するカーネルの内部配列へのインデックスである。
417 .\"O (i.e., the current value)
418 .\"O for all semaphores of the set into
423 .\"O The calling process must have read permission on the semaphore set.
431 呼び出したプロセスはそのセマフォ集合に読み込み許可を持たなければならない。
434 .\"O The system call returns the value of
438 .\"O semaphore of the set
439 .\"O (i.e., the number of processes waiting for an increase of
443 .\"O semaphore of the set).
444 .\"O The calling process must have read permission on the semaphore set.
454 呼び出したプロセスはそのセマフォ集合に読み込み許可を持たなければならない。
457 .\"O The system call returns the value of
461 .\"O semaphore of the set
462 .\"O (i.e., the PID of the process that executed the last
466 .\"O semaphore of the set).
467 .\"O The calling process must have read permission on the semaphore set.
476 コールを実行したプロセスの PID) を返す。
477 呼び出したプロセスはそのセマフォ集合に読み込み許可を持たなければならない。
480 .\"O The system call returns the value of
484 .\"O semaphore of the set.
485 .\"O The calling process must have read permission on the semaphore set.
491 呼び出したプロセスはそのセマフォ集合に読み込み許可を持たなければならない。
494 .\"O The system call returns the value of
498 .\"O semaphore of the set
499 .\"O (i.e., the number of processes waiting for
503 .\"O semaphore of the set to become 0).
504 .\"O The calling process must have read permission on the semaphore set.
513 の値が 0 になるのを待っているプロセスの数を返す)。
514 呼び出したプロセスはそのセマフォ集合に読み込み許可を持たなければならない。
519 .\"O for all semaphores of the set using
521 .\"O updating also the
525 .\"O structure associated with the set.
536 .\"O Undo entries (see
538 .\"O are cleared for altered semaphores in all processes.
539 .\"O If the changes to semaphore values would permit blocked
541 .\"O calls in other processes to proceed, then those processes are woken up.
542 全てのプロセスのセマフォの変更についてのアンドゥ・エントリ
544 を参照) は消去 (clear) される。
545 セマフォの値の変更により、他のプロセス内でブロックされている
547 コールの続行が許可されると、それらのプロセスは起こされる (wake up)。
551 .\"O The calling process must have alter (write) permission on
552 .\"O the semaphore set.
556 変更 (書き込み) 許可を持たなければならない。
559 .\"O Set the value of
565 .\"O semaphore of the set, updating also the
569 .\"O structure associated with the set.
581 .\"O Undo entries are cleared for altered semaphores in all processes.
582 .\"O If the changes to semaphore values would permit blocked
584 .\"O calls in other processes to proceed, then those processes are woken up.
585 .\"O The calling process must have alter permission on the semaphore set.
586 全てのプロセスのセマフォの変更についてのアンドゥ・エントリは消去される。
587 セマフォの値の変更により、他のプロセス内でブロックされている
589 コールの続行が許可されると、それらのプロセスは起こされる (wake up)。
591 変更 (書き込み) 許可を持たなければならない。
592 .\"O .SH "RETURN VALUE"
599 .\"O indicating the error.
606 .\"O Otherwise the system call returns a nonnegative value depending on
638 .\"O the index of the highest used entry in the
639 .\"O kernel's internal array recording information about all
641 .\"O (This information can be used with repeated
643 .\"O operations to obtain information about all semaphore sets on the system.)
644 全てのセマフォ集合に関する情報を管理しているカーネルの内部配列の使用中
646 (この情報は、システムの全てのセマフォ集合に関する情報を取得するために
657 .\"O the identifier of the semaphore set whose index was given in
660 で指定されたインデックスを持つセマフォ集合の識別子
664 .\"O values return 0 on success.
666 の値がそれ以外の場合、成功すると 0 が返される。
671 .\"O will be set to one of the following:
679 .\"O has one of the values
690 .\"O and the calling process does not have the required
691 .\"O permissions on the semaphore set and does not have the
692 .\"O .B CAP_IPC_OWNER
706 呼び出したプロセスがセマフォに対して必要とされる許可と
708 ケーパビリティ (capability) を持っていない。
711 .\"O The address pointed to by
715 .\"O isn't accessible.
719 で指されているアドレスにアクセスすることができない。
722 .\"O The semaphore set was removed.
726 .\"O Invalid value for
732 .\"O operation, the index value specified in
734 .\"O referred to an array slot that is currently unused.
743 で指定されたインデックス値が現在未使用の配列のスロットを参照いていた。
752 .\"O but the effective user ID of the calling process is not the creator
754 .\"O .IR sem_perm.cuid )
757 .\"O .IR sem_perm.uid )
758 .\"O of the semaphore set,
759 .\"O and the process does not have the
760 .\"O .B CAP_SYS_ADMIN
767 が指定され、呼び出したプロセスの実効ユーザ ID がセマフォの
783 .\"O and the value to which
785 .\"O is to be set (for some semaphore of the set) is less than 0
786 .\"O or greater than the implementation limit
795 に設定される値が 0 より小さいか、実装の制限
798 .\"O .SH "CONFORMING TO"
801 .\"O .\" SVr4 documents more error conditions EINVAL and EOVERFLOW.
802 .\" SVr4 には、他に EINVAL, EOVERFLOW エラーについての記述がある。
810 .\"O operations are used by the
812 .\"O program to provide information on allocated resources.
813 .\"O In the future these may modified or moved to a /proc file system
820 プログラムによって割当られた資源について情報を提供するために使用される。
822 /proc ファイル・システム・インタフェースに移動されるかもしれない。
824 .\"O Various fields in a \fIstruct semid_ds\fP were typed as
829 .\"O under Linux 2.4.
830 .\"O To take advantage of this,
831 .\"O a recompilation under glibc-2.1.91 or later should suffice.
832 .\"O (The kernel distinguishes old and new calls by an
836 \fI構造体 semid_ds\fP 内の多くのフィールドは、
842 この利点を生かすには、glibc-2.1.91 以降の環境下で
844 カーネルは新しい形式の呼び出しと古い形式の呼び出しを
850 .\"O In some earlier versions of glibc, the
852 .\"O union was defined in \fI<sys/sem.h>\fP, but POSIX.1-2001 requires
853 .\"O that the caller define this union.
856 共用体は \fI<sys/sem.h>\fP で定義されていたが、
857 POSIX.1-2001 では呼び出し側がこの共用体を定義する必要がある。
858 .\"O On versions of glibc where this union is \fInot\fP defined,
860 .\"O .B _SEM_SEMUN_UNDEFINED
861 .\"O is defined in \fI<sys/sem.h>\fP.
862 この共用体が定義されて\fIいない\fP glibc のバージョンでは、
864 .B _SEM_SEMUN_UNDEFINED
865 が \fI<sys/sem.h>\fP で定義されている。
867 .\"O The following system limit on semaphore sets affects a
872 コールに影響するセマフォ集合のシステム制限:
875 .\"O Maximum value for
877 .\"O implementation dependent (32767).
881 .\"O For greater portability it is best to always call
883 .\"O with four arguments.
884 移植性を高めるための一番良い方法は、常に 4 個の引き数で
892 .BR capabilities (7),
893 .BR sem_overview (7),