.\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it) .\" .\" 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. .TH IPC 5 "November 1, 1993" "Linux 0.99.13" "Linux Programmer's Manual" .SH NAME ipc \- System V 程序間通訊機制 .SH SYNOPSIS 總覽 .nf .B # include .B # include .B # include .B # include .B # include .SH DESCRIPTION 本手冊頁涉及 System V 程序間通訊機制在 Linux 下的實現: 訊息佇列, 訊號燈集合, 以及共享記憶體段. 下面提到 .B 資源 時, 就是指上面這些通訊機制中的一種. .SS 資源訪問許可權 對每個資源, 系統用一個共有的 .BR "struct ipc_perm" 結構來存放許可權資訊, 以確定一個 ipc 操作是否可訪問該資源. 在 .I 中定義了 .B ipc_perm, 其成員如下: .sp .B ushort cuid; /* 建立者 uid */ .br .B ushort cgid; /* 建立者 gid */ .br .B ushort uid; /* 所有者 uid */ .br .B ushort gid; /* 所有者 gid */ .br .B ushort mode; /* 讀/寫許可權 */ .PP 結構 .B ipc_perm 的成員 .B mode 的低九位定義了對該資源的訪問許 可, 以確定一個執行了 ipc 系統呼叫的程序能否訪問該資源. 其解 釋如下: .sp .nf 0400 使用者可讀. 0200 使用者可寫. .sp .5 0040 組成員可讀. 0020 組成員可寫. .sp .5 0004 其他使用者可讀. 0002 其他使用者可寫. .fi .PP 系統沒有使用執行位 0100, 0010 和 0001. 另外, 這裡的 "可寫" 等 效於訊號燈集合裡的 "可更改". .PP 在 .I 系統標頭檔案裡還定義瞭如下符號常數: .TP 14 .B IPC_CREAT 如果 key 不存在就建立. .TP .B IPC_EXCL 如果 key 已經存在則失敗. .TP .B IPC_NOWAIT 如果請求必須等待, 產生錯誤. .TP .B IPC_PRIVATE 私有 key. .TP .B IPC_RMID 刪除資源. .TP .B IPC_SET 設定資源選項. .TP .B IPC_STAT 取得資源選項. .PP 請注意 .B IPC_PRIVATE 是一個 .B key_t 型別, 而別的符號常數都是標誌域,它們的可以或( OR )在一起形成 .B int 型別. .SS 訊息佇列 訊息佇列由正整數 .RI "(它的 " msqid ) 唯一標識, 其結構體 .BR "struct msquid_ds" 在 .IR 中定義, 包含如下成員: .sp .B struct ipc_perm msg_perm; .br .B ushort msg_qnum; /* 佇列中訊息數目 */ .br .B ushort msg_qbytes; /* 一條佇列最大位元組數 */ .br .B ushort msg_lspid; /* 上一次 msgsnd 呼叫的 pid */ .br .B ushort msg_lrpid; /* 上一次 msgrcv 呼叫的 pid */ .br .B time_t msg_stime; /* 上一次 msgsnd 的時間 */ .br .B time_t msg_rtime; /* 上一次 msgrcv 的時間 */ .br .B time_t msg_ctime; /* 上一次修改時間 */ .TP 11 .B msg_perm .B ipc_perm 結構, 指明瞭對該訊息佇列的訪問許可權. .TP .B msg_qnum 該隊列當前的訊息總數. .TP .B msg_qbytes 該佇列所允許的訊息正文最大位元組總數. .TP .B msg_lspid 最後做 .B msgsnd 系統呼叫的程序的 ID. .TP .B msg_lrpid 最後做 .B msgrcv 系統呼叫的程序的 ID. .TP .B msg_stime 最近做 .B msgsnd 系統呼叫的時間. .TP .B msg_rtime 最近做 .B msgrcv 系統呼叫的時間. .TP .B msg_ctime 最後一次改變 .B msqid_ds 結構成員的時間. .SS 訊號燈集合 訊號燈集合由正整數 .RI "(它的 " semid ) 唯一標識, 並有一個與之關聯的結構體 .BR "struct semid_ds" 它在 .IR 中定義, 包含如下成員: .sp .B struct ipc_perm sem_perm; .br .B time_t sem_otime; /* 上一次操作的時間 */ .br .B time_t sem_ctime; /* 上一次修改的時間 */ .br .B ushort sem_nsems; /* 集合中訊號燈數目 */ .TP 11 .B sem_perm .B ipc_perm 結構, 指明對該訊號燈集合的訪問許可權. .TP .B sem_otime 最近做 .B semop 系統呼叫的時間. .TP .B sem_ctime 最近做 .B semctl 系統呼叫的時間, 該呼叫修改了上面結構的一個成員 或者改變了屬於該集合的一個訊號燈. .TP .B sem_nsems 該訊號燈集合的訊號燈數目. 集合中每個訊號燈都可以用從 .B 0 到 .BR sem_nsems\-1 的一個非負整數來引用. .PP 一個訊號燈就是一個 .B "struct sem" 結構, 包含如下成員: .sp .B ushort semval; /* 訊號燈值 */ .br .B short sempid; /* 上一次操作的程序的 pid */ .br .B ushort semncnt; /* 等待增加 semval 值的程序數目 */ .br .B ushort semzcnt; /* 等待 semval = 0 的程序數目 */ .TP 11 .B semval 該訊號燈值,是一個非負整數. .TP .B sempid 最後一個對該訊號燈做操作的程序 ID. .TP .B semncnt 等待增加 .B semval 的程序數. .TP .B semznt 等待 .B semval 變成 0 的程序數. .SS 共享記憶體段 共享記憶體段由正整數 .RI "(它的 " shmid ) 唯一標識, 有一個關聯的結構型別 .BR "struct shmid_ds" 在 .IR 中定義, 包含如下成員: .sp .B struct ipc_perm shm_perm; .br .B int shm_segsz; /* 段尺寸 */ .br .B ushort shm_cpid; /* 建立者 pid */ .br .B ushort shm_lpid; /* 上一次操作的程序的 pid */ .br .B short shm_nattch; /* 目前附著的程序數目 */ .br .B time_t shm_atime; /* 上一次附著的時間 */ .br .B time_t shm_dtime; /* 上一次脫離的時間 */ .br .B time_t shm_ctime; /* 上一次修改的時間 */ .TP 11 .B shm_perm .B ipc_perm 結構, 指明對共享記憶體段的訪問許可權. .TP .B shm_segsz 共享記憶體段的大小, 以位元組為單位. .TP .B shm_cpid 建立該共享記憶體段的程序的 ID. .TP .B shm_lpid 最後執行 .B shmat 或者 .B shmdt 系統呼叫的程序 ID. .TP .B shm_nattch 當前對該共享記憶體段的活躍連線數. .TP .B shm_atime 最後做 .B shmat 系統呼叫的時間. .TP .B shm_dtime 最後做 .B shmdt 系統呼叫的時間. .TP .B shm_ctime 最後做 .B shmctl 系統呼叫的時間, 如果該呼叫改變了 shmid_ds. .SH "又見" .BR ftok (3), .BR msgctl (2), .BR msgget (2), .BR msgrcv (2), .BR msgsnd (2), .BR semctl (2), .BR semget (2), .BR semop (2), .BR shmat (2), .BR shmctl (2), .BR shmget (2), .BR shmdt (2). .SH "[中文版維護人]" .B name .SH "[中文版最新更新]" .BR 2001/02/02 .SH "《中國 Linux 論壇 man 手冊頁翻譯計劃》:" .BI http://cmpp.linuxforum.net .SH "跋" .br 本頁面中文版由中文 man 手冊頁計劃提供。 .br 中文 man 手冊頁計劃:\fBhttps://github.com/man-pages-zh/manpages-zh\fR