sem_openのヘルプ・マニュアル
日本語 英語
sem_open --help
man sem_open
SEM_OPEN(3) Linux Programmer’s Manual SEM_OPEN(3)
名前
sem_open - 名前付きセマフォを初期化し、オープンする
書式
#include /* For O_* constants */
#include /* For mode constants */
#include
sem_t *sem_open(const char *name, int oflag);
sem_t *sem_open(const char *name, int oflag,
mode_t mode, unsigned int value);
-lrt または -pthread でリンクする。
説明
sem_open() は、新規の POSIX セマフォを作成するか、既存のセマフォのオー
プンを行う。セマフォは name で識別される。 name の 構 成 の 詳 細 は
sem_overview(7) を参照。
oflag 引き数には、 sem_open() の動作を制御するフラグを指定する (oflag
の値の定義は のインクルードにより得られる)。 oflag に O_CREAT
が 指定されると、まだ存在しない場合にはそのセマフォが作成される。セマフ
ォの所有者 (ユーザ ID)、グループ所有権 (グループ ID) には、それぞれ呼び
出 し 元プロセスの実効 UID、実効 GID が設定される。 oflag に O_CREAT と
O_EXCL の両方が指定された場合、指定された名前 name のセマフォがすでに存
在するとエラーが返される。
oflag に O_CREAT を指定する場合、さらに引き数が 2 つ必要である。 mode
引き数は、 open(2) と同じように、新しいセマフォに設定されるアクセス許可
(permission) を指定する。許可設定はプロセスの umask でマスクされる (許
可ビットのシンボル定義は のインクルードにより得られる)。セ
マ フォにアクセスしようとするユーザは、読み出し許可と書き込み許可の両方
を得る必要がある。 value 引き数は新しいセマフォの初期値を指 定 す る 。
O_CREAT が指定され、指定した名前 name のセマフォがすでに存在する場合、
mode と value は無視される。
返り値
成功すると、 sem_open() は新しいセマフォのアドレスを返す。このアドレ ス
は 他 の セ マ フ ォ 関連の関数を呼び出す際に使用される。エラーの場合、
sem_open() は SEM_FAILED を返し、 errno にエラーを示す値をセットする。
エラー
EACCES そのセマフォが存在するが、呼び出し元にはそのセマフォをオープンす
る許可がない。
EEXIST oflag に O_CREAT と O_EXCL の両方が指定されたが、 name という名
前のセマフォはすでに存在する。
EINVAL value が SEM_VALUE_MAX よりも大きい。
EINVAL name が "/" だけで構成され、その後ろに他の文字が続いていなかった
。
EMFILE オープンされたファイル数がすでにそのプロセスにおける上限に達して
いる。
ENAMETOOLONG
name が長すぎる。
ENFILE オープンされたファイル総数がシステム全体での上限に達している。
ENOENT oflag に O_CREAT フラグが指定されておらず、 name という名前の セ
マ フォも存在しない。または、 O_CREAT が指定されたが、 name が適
切な形式ではなかった。
ENOMEM 十分なメモリがない。
準拠
POSIX.1-2001.
関連項目
sem_close(3), sem_getvalue(3), sem_post(3), sem_unlink(3), sem_wait(3),
sem_overview(7)
Linux 2009-02-20 SEM_OPEN(3)
SEM_OPEN(3) Linux Programmer’s Manual SEM_OPEN(3)
NAME
sem_open - initialize and open a named semaphore
SYNOPSIS
#include /* For O_* constants */
#include /* For mode constants */
#include
sem_t *sem_open(const char *name, int oflag);
sem_t *sem_open(const char *name, int oflag,
mode_t mode, unsigned int value);
Link with -lrt or -pthread.
DESCRIPTION
sem_open() creates a new POSIX semaphore or opens an existing
semaphore. The semaphore is identified by name. For details of the
construction of name, see sem_overview(7).
The oflag argument specifies flags that control the operation of the
call. (Definitions of the flags values can be obtained by including
.) If O_CREAT is specified in oflag, then the semaphore is
created if it does not already exist. The owner (user ID) of the
semaphore is set to the effective user ID of the calling process. The
group ownership (group ID) is set to the effective group ID of the
calling process. If both O_CREAT and O_EXCL are specified in oflag,
then an error is returned if a semaphore with the given name already
exists.
If O_CREAT is specified in oflag, then two additional arguments must be
supplied. The mode argument specifies the permissions to be placed on
the new semaphore, as for open(2). (Symbolic definitions for the per-
missions bits can be obtained by including .) The permis-
sions settings are masked against the process umask. Both read and
write permission should be granted to each class of user that will
access the semaphore. The value argument specifies the initial value
for the new semaphore. If O_CREAT is specified, and a semaphore with
the given name already exists, then mode and value are ignored.
RETURN VALUE
On success, sem_open() returns the address of the new semaphore; this
address is used when calling other semaphore-related functions. On
error, sem_open() returns SEM_FAILED, with errno set to indicate the
error.
ERRORS
EACCES The semaphore exists, but the caller does not have permission to
open it.
EEXIST Both O_CREAT and O_EXCL were specified in oflag, but a semaphore
with this name already exists.
EINVAL value was greater than SEM_VALUE_MAX.
EINVAL name consists of just "/", followed by no other characters.
EMFILE The process already has the maximum number of files and open.
ENAMETOOLONG
name was too long.
ENFILE The system limit on the total number of open files has been
reached.
ENOENT The O_CREAT flag was not specified in oflag and no semaphore
with this name exists; or, O_CREAT was specified, but name
wasn’t well formed.
ENOMEM Insufficient memory.
CONFORMING TO
POSIX.1-2001.
SEE ALSO
sem_close(3), sem_getvalue(3), sem_post(3), sem_unlink(3), sem_wait(3),
sem_overview(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2009-02-20 SEM_OPEN(3)