Interprocess Communication
The following message passing, semaphore and shared memory services form an Interprocess Communication facility. Certain aspects of their operation are common, and are described below.
IPC Functions msgctl() msgget() msgrcv() msgsnd() semctl() semget() semop() shmat() shmctl() shmdt() shmget() Another Interprocess Communication facility is provided by functions in the Realtime Feature Group.
IPC General Description
Each individual shared memory segment, message queue and semaphore set is identified by a unique positive integer, called respectively a shared memory identifier, shmid, a semaphore identifier, semid, and a message queue identifier, msqid. The identifiers are returned by calls on shmget(), semget() and msgget(), respectively. Associated with each identifier is a data structure which contains data related to the operations which may be or may have been performed. See <sys/shm.h>, <sys/sem.h> and <sys/msg.h> for their descriptions.
Each of the data structures contains both ownership information and an ipc_perm structure, see <sys/ipc.h>, which are used in conjunction to determine whether or not read/write (read/alter for semaphores) permissions should be granted to processes using the IPC facilities. The mode member of the ipc_perm structure acts as a bit field which determines the permissions.
The values of the bits are given below in octal notation.
Bit Meaning 0400 Read by user 0200 Write by user 0040 Read by group 0020 Write by group 0004 Read by others 0002 Write by others The name of the ipc_perm structure is shm_perm, sem_perm or msg_perm, depending on which service is being used. In each case, read and write/alter permissions are granted to a process if one or more of the following are true (xxx is replaced by shm, sem or msg, as appropriate):
- The process has appropriate privileges.
- The effective user ID of the process matches xxx_perm.cuid or xxx_perm.uid in the data structure associated with the IPC identifier and the appropriate bit of the user field in xxx_perm.mode is set.
- The effective user ID of the process does not match xxx_perm.cuid or xxx_perm.uid but the effective group ID of the process matches xxx_perm.cgid or xxx_perm.gid in the data structure associated with the IPC identifier, and the appropriate bit of the group field in xxx_perm.mode is set.
- The effective user ID of the process does not match xxx_perm.cuid or xxx_perm.uid and the effective group ID of the process does not match xxx_perm.cgid or xxx_perm.gid in the data structure associated with the IPC identifier, but the appropriate bit of the other field in xxx_perm.mode is set.
Otherwise, the permission is denied.