I'm very pleased to announce the release of our new website and documentation using the new toolchain with Hugo and AsciiDoctor. To get more information about the new toolchain please read the FreeBSD Documentation Project Primer[1], Hugo docs[2] and AsciiDoctor docs[3]. Acknowledgment: Benedict Reuschling <bcr@> Glen Barber <gjb@> Hiroki Sato <hrs@> Li-Wen Hsu <lwhsu@> Sean Chittenden <seanc@> The FreeBSD Foundation [1] https://docs.FreeBSD.org/en/books/fdp-primer/ [2] https://gohugo.io/documentation/ [3] https://docs.asciidoctor.org/home/ Approved by: doceng, core
143 lines
3.9 KiB
Groff
143 lines
3.9 KiB
Groff
.\"
|
|
.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
|
|
.\"
|
|
.\" All rights reserved.
|
|
.\"
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
.\" modification, are permitted provided that the following conditions
|
|
.\" are met:
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
.\"
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
.\"
|
|
.\" %FreeBSD: src/lib/libc/sys/semget.2,v 1.15 2004/07/02 23:52:13 ru Exp %
|
|
.\"
|
|
.\" $FreeBSD$
|
|
.Dd September 12, 1995
|
|
.Dt SEMGET 2
|
|
.Os
|
|
.Sh 名称
|
|
.Nm semget
|
|
.Nd セマフォ ID を取得する
|
|
.Sh ライブラリ
|
|
.Lb libc
|
|
.Sh 書式
|
|
.In sys/types.h
|
|
.In sys/ipc.h
|
|
.In sys/sem.h
|
|
.Ft int
|
|
.Fn semget "key_t key" "int nsems" "int flag"
|
|
.Sh 解説
|
|
.Fa key
|
|
と
|
|
.Fa flag
|
|
の値に基づき、
|
|
.Fn semget
|
|
は新たに作成された、あるいは
|
|
以前から存在するセマフォ集合の識別子を返します。
|
|
.\"
|
|
.\" This is copied verbatim from the shmget manpage. Perhaps
|
|
.\" it should go in a common manpage, such as .Xr ipc 2
|
|
.\"
|
|
キーはファイル名に類似しています。
|
|
キーは IPC オブジェクトに名前を付けるハンドルを提供します。
|
|
キーを指定する方法は 3 つあります:
|
|
.Bl -bullet
|
|
.It
|
|
IPC_PRIVATE
|
|
を指定できます。
|
|
この場合、新しい IPC オブジェクトが作成されます。
|
|
.It
|
|
整数定数を指定できます。
|
|
.Fa key
|
|
に対応する IPC オブジェクトが指定されておらず、
|
|
しかも IPC_CREAT ビットを
|
|
.Fa flag
|
|
引数で設定している場合、新しい IPC オブジェクトが作成されます。
|
|
.It
|
|
.Xr ftok 3
|
|
関数を使用して、パス名からキーを生成できます。
|
|
.El
|
|
.\"
|
|
.\" Likewise for this section, except SHM_* becomes SEM_*.
|
|
.\"
|
|
.Pp
|
|
新しく作成される IPC オブジェクトのモードは、次の定数の論理和 (
|
|
.Em OR
|
|
) を
|
|
.Fa flag
|
|
引数に設定することで決定されます:
|
|
.Bl -tag -width XSEM_WXX6XXX
|
|
.It Dv SEM_R
|
|
ユーザ用の読取りアクセス
|
|
.It Dv SEM_A
|
|
ユーザ用の書換えアクセス
|
|
.It Dv ( SEM_R>>3 )
|
|
グループ用の読取りアクセス
|
|
.It Dv ( SEM_A>>3 )
|
|
グループ用の書換えアクセス
|
|
.It Dv ( SEM_R>>6 )
|
|
その他用の読取りアクセス
|
|
.It Dv ( SEM_A>>6 )
|
|
その他用の書換えアクセス
|
|
.El
|
|
.Pp
|
|
新しいセマフォ集合が作成されている場合、
|
|
.Fa nsems
|
|
を使用して、集合の中に入れる必要のあるセマフォの数を示します。
|
|
そうでない場合、
|
|
.Fa nsems
|
|
を 0 として指定できます。
|
|
.Sh 戻り値
|
|
.Fn semget
|
|
システムコールは、正常に完了するとセマフォ集合の識別子を返します。
|
|
そうでない場合は、-1 を返し、エラーを示すように
|
|
.Va errno
|
|
を設定します。
|
|
.Sh エラー
|
|
.Fn semget
|
|
システムコールは次の場合に処理に失敗します:
|
|
.Bl -tag -width Er
|
|
.\" ipcperm could fail (we're opening to read and write, as it were)
|
|
.It Bq Er EACCES
|
|
アクセスパーミッション障害。
|
|
.\"
|
|
.\" sysv_sem.c is quite explicit about these, so I'm pretty sure
|
|
.\" this is accurate
|
|
.\"
|
|
.It Bq Er EEXIST
|
|
IPC_CREAT および IPC_EXCL が指定されているのに、
|
|
.Fa key
|
|
に対応するセマフォ集合が既に存在します。
|
|
.It Bq Er EINVAL
|
|
要求されたセマフォの数が、
|
|
システムが集合単位で課している最大値を超過しています。
|
|
.It Bq Er ENOSPC
|
|
利用可能なセマフォが不足しています。
|
|
.It Bq Er ENOSPC
|
|
カーネルが
|
|
.Fa "struct semid_ds"
|
|
を割り当てられませんでした。
|
|
.It Bq Er ENOENT
|
|
.Fa key
|
|
に対応するセマフォ集合が見つからず、その際に
|
|
IPC_CREAT
|
|
が指定されていませんでした。
|
|
.El
|
|
.Sh 関連項目
|
|
.Xr semctl 2 ,
|
|
.Xr semop 2 ,
|
|
.Xr ftok 3
|