.\" Copyright (c) 1993 Luigi P. Bai (lpb@softint.com) July 28, 1993 .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Modified Wed Jul 28 10:57:35 1993, Rik Faith .\" Modified Sun Nov 28 16:43:30 1993, Rik Faith .\" with material from Giorgio Ciucci .\" Portions Copyright 1993 Giorgio Ciucci .\" Modified Tue Oct 22 22:03:17 1996 by Eric S. Raymond .\" Modified, 8 Jan 2003, Michael Kerrisk, .\" Removed EIDRM from errors - that can't happen... .\" Modified, 27 May 2004, Michael Kerrisk .\" Added notes on capability requirements .\" Modified, 11 Nov 2004, Michael Kerrisk .\" Language and formatting clean-ups .\" Added notes on /proc files .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya .\" all rights reserved. .\" Translated 1997-03-01, HANATAKA Shinya .\" Updated & Modified 2001-06-03, Yuichi SATO .\" Updated 2001-12-22, Kentaro Shirakata .\" Updated 2002-10-16, Kentaro Shirakata .\" Updated 2003-02-23, Kentaro Shirakata .\" Updated 2005-03-02, Akihiro MOTOKI .\" Updated 2005-11-04, Akihiro MOTOKI .\" Updated 2006-07-21, Akihiro MOTOKI, LDP v2.36 .\" Updated 2013-05-06, Akihiro MOTOKI .\" Updated 2013-07-24, Akihiro MOTOKI .\" .TH SHMGET 2 2014\-04\-17 Linux "Linux Programmer's Manual" .SH 名前 shmget \- System V 共有メモリ・セグメントを割り当てる .SH 書式 .ad l \fB#include \fP .br \fB#include \fP .sp \fBint shmget(key_t \fP\fIkey\fP\fB, size_t \fP\fIsize\fP\fB, int \fP\fIshmflg\fP\fB);\fP .ad b .SH 説明 \fBshmget\fP() は \fIkey\fP 引き数に対応する System V 共有メモリ・セグメントの識別子を返す。 \fIkey\fP の値が \fBIPC_PRIVATE\fP の場合、もしくは \fIkey\fP に対応する共有メモリ・セグメントが存在せず、 \fIshmflg\fP に \fBIPC_CREAT\fP が指定されていた場合、 新しい共有メモリ・セグメントを作成する。 作成される共有メモリ・セグメントは、 \fIsize\fP 引き数の値を \fBPAGE_SIZE\fP の倍数へと切り上げた (round up) 大きさとなる。 .PP \fIshmflg\fP に \fBIPC_CREAT\fP と \fBIPC_EXCL\fP の両方が指定された場合、 \fIkey\fP に対応する共有メモリ・セグメントが既に存在すると、 \fBshmget\fP() は失敗し、 \fIerrno\fP に \fBEEXIST\fP が設定される (これは \fBopen\fP(2) に \fBO_CREAT | O_EXCL\fP を指定した場合の動作と同じである)。 .PP \fIshmflg\fP は以下の内容から構成される: .TP 12 \fBIPC_CREAT\fP 新しいセグメントを作成する。このフラグが指定されなかった場合、 \fBshmget\fP() は \fIkey\fP に対応するセグメントを探し、 ユーザがそのセグメントにアクセスする許可があるかどうかをチェックする。 .TP \fBIPC_EXCL\fP \fBIPC_CREAT\fP と共に使用し、セグメントが既に存在した場合には 失敗することを保証する。 .TP \fImode_flags\fP (下位 9 ビット) 所有者、グループ、他人 (world) への許可を指定する。 これらのビットは \fBopen\fP(2) の \fImode\fP 引き数と同じ形式で同じ意味を持つ。 今のところ、システムは実行 (execute) 許可を参照しない。 .TP \fBSHM_HUGETLB\fP (Linux 2.6 以降) "ヒュージページ (huge page)" を使うセグメントを割り当てる。詳細な情報は、Linux カーネルソースのファイル \fIDocumentation/vm/hugetlbpage.txt\fP を参照。 .TP \fBSHM_NORESERVE\fP (Linux 2.6.15 以降) .\" As at 2.6.17-rc2, this flag has no effect if SHM_HUGETLB was also .\" specified. このフラグは、 \fBmmap\fP(2) の \fBMAP_NORESERVE\fP フラグと同じ役割を果たす。 このセグメントに対するスワップ空間の予約を行わない。 スワップ空間を予約した場合は、そのセグメントの変更が必ず成功することが 保証される。スワップ空間の予約を行わなかった場合は、物理メモリに空きが ないと書き込み時に \fBSIGSEGV\fP を受け取る可能性がある。 \fBproc\fP(5) にある \fI/proc/sys/vm/overcommit_memory\fP ファイルに関する議論も参照のこと。 .PP 共有メモリ・セグメントが新たに作成される際、 共有メモリ・セグメントの内容は 0 で初期化され、 関連情報を保持するデータ構造体 \fIshmid_ds\fP は以下のように初期化される。 .IP \fIshm_perm.cuid\fP と \fIshm_perm.uid\fP に呼び出し元プロセスの実効 (effective) ユーザーID を設定する。 .IP \fIshm_perm.cgid\fP と \fIshm_perm.gid\fP に呼び出し元プロセスの実効グループID を設定する。 .IP \fIshm_perm.mode\fP の下位 9 ビットに \fIshmflg\fP の下位 9 ビットを設定する。 .IP \fIshm_segsz\fP に \fIsize\fP の値を設定する。 .IP \fIshm_lpid\fP, \fIshm_nattch\fP, \fIshm_atime\fP, \fIshm_dtime\fP に 0 を設定する。 .IP \fIshm_ctime\fP に現在の時刻を設定する。 .PP 共有メモリ・セグメントが既に存在する場合、アクセス許可の検査と、 破壊 (destruction) マークがつけられていないかのチェックが行われる。 .SH 返り値 成功の場合、有効な共有メモリ・セグメントの識別子が返される。 エラーの場合、 \-1 が返り、 \fIerror\fP にエラーを示す値が設定される。 .SH エラー 失敗した場合は \fIerrno\fP が以下のどれかに設定される: .TP \fBEACCES\fP ユーザーはその共有メモリ・セグメントへのアクセス許可を持たず、 \fBCAP_IPC_OWNER\fP ケーパビリティも持っていない。 .TP \fBEEXIST\fP \fBIPC_CREAT | IPC_EXCL\fP が指定されていたが、そのセグメントが既に存在する。 .TP \fBEINVAL\fP 新しいセグメントを作成しようとした際に \fIsize\fP < \fBSHMMIN\fP または \fIsize\fP > \fBSHMMAX\fP であった。 もしくは、指定されたキーに対応するセグメントが既に存在して、新しい セグメントを作成しようとはしなかったが、\fIsize\fP が存在するセグメントの サイズよりも大きかった。 .TP \fBENFILE\fP .\" [2.6.7] shmem_zero_setup()-->shmem_file_setup()-->get_empty_filp() システム全体でオープンされているファイルの総数が上限に達した。 .TP \fBENOENT\fP 指定された \fIkey\fP に対応するセグメントが存在せず、 \fBIPC_CREAT\fP も指定されていなかった。 .TP \fBENOMEM\fP セグメントの管理情報 (overhead) に割り当てるメモリがなかった。 .TP \fBENOSPC\fP システム全体の共有メモリ・セグメント数の制限 (\fBSHMMNI\fP) に達した、または要求された \fIsize\fP のセグメントの割り当てが システム全体の共有メモリサイズの制限 (\fBSHMALL\fP) を超過した。 .TP \fBEPERM\fP \fBSHM_HUGETLB\fP フラグが指定されたが、呼び出し元には権限がなかった (\fBCAP_IPC_LOCK\fP ケーパビリティを持っていなかった)。 .SH 準拠 .\" SVr4 documents an additional error condition EEXIST. SVr4, POSIX.1\-2001. \fBSHM_HUGETLB\fP は Linux での拡張であり、移植性はない。 .SH 注意 .\" Like Linux, the FreeBSD man pages still document .\" the inclusion of these header files. Linux や POSIX の全てのバージョンでは、 \fI\fP と \fI\fP のインクルードは必要ない。しかしながら、いくつかの古い実装ではこれらのヘッダファイルのインクルードが必要であり、 SVID でもこれらのインクルードをするように記載されている。このような古いシステムへの移植性を意図したアプリケーションではこれらのファイルをインクルードする必要があるかもしれない。 \fBIPC_PRIVATE\fP はフラグではなく \fIkey_t\fP 型である。 この特別な値が \fIkey\fP に使用された場合は、 \fBshmget\fP() は \fIshmflg\fP の下位 9 ビットを除いた全てを無視し、 (成功すれば) 新しい共有メモリ・セグメントを作成する。 .PP \fBshmget\fP() コールに影響する共有メモリ・セグメント資源の制限は以下の通りである: .TP \fBSHMALL\fP システム全体の共有メモリ・ページの最大数。 Linux 2.2 以降では、この上限値のデフォルトは以下である。 SHMMAX / PAGE_SIZE * (SHMMNI / 16) 4kB ページサイズと仮定すると、 (Linux 2.4 以降では) この式の結果は 2^20 (2,097,152) になる。 Linux では、この上限値は \fI/proc/sys/kernel/shmall\fP 経由で参照したり、変更したりできる。 .TP \fBSHMMAX\fP 共有メモリ・セグメントの最大バイト数。 Linux 2.2 以降では、 この上限値のデフォルトは 0x2000000 (32MB) である。 Linux では、この上限値は \fI/proc/sys/kernel/shmmax\fP 経由で参照したり、変更したりできる。 .TP \fBSHMMIN\fP 共有メモリ・セグメントのバイト単位の大きさの下限: 実装依存 (現在は 1 バイトだが、実質的な最小サイズは \fBPAGE_SIZE\fP である)。 .TP \fBSHMMNI\fP システム全体の共有メモリ・セグメントの最大数。 この上限値のデフォルトは、 Linux 2.2 以降では 128、 Linux 2.4 以降で 4096 である。 .\" Kernels between 2.4.x and 2.6.8 had an off-by-one error that meant .\" that we could create one more segment than SHMMNI -- MTK .\" This /proc file is not available in Linux 2.2 and earlier -- MTK Linux では、この上限値は \fI/proc/sys/kernel/shmmni\fP 経由で参照したり、変更したりできる。 .PP プロセス当りの共有メモリ・セグメントの個数の最大値 (\fBSHMSEG\fP) に関する実装上の制限はない。 .SS "Linux での注意" バージョン 2.3.30 までは、Linux は 削除が予定されている共有メモリ・セグメントに対して \fBshmget\fP() が行われると \fBEIDRM\fP を返していた。 .SH バグ \fBIPC_PRIVATE\fP という名前を選んだのはおそらく失敗であろう。 \fBIPC_NEW\fP の方がより明確にその機能を表しているだろう。 .SH 関連項目 \fBshmat\fP(2), \fBshmctl\fP(2), \fBshmdt\fP(2), \fBftok\fP(3), \fBcapabilities\fP(7), \fBshm_overview\fP(7), \fBsvipc\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。