Next: , Previous: perms, Up: Overview



1.4 IPC system calls

This section provides an overview of the IPC system calls. See the specific sections on each type of resource for details.

Each type of mechanism provides a get, ctl and one or more op system calls that allow the user to create or procure the resource (get), define its behaviour or destroy it (ctl) and manipulate the resources (op).

1.4.1 The get system calls

The get call typically takes a key and returns a numeric id that is used for further access. The id is an index into the resource table. A sequence number is maintained and incremented when a resource is destroyed so that access using an obsolete id is likely to fail.

The user also specifies the permissions and other behaviour charecteristics for the current access. The flags are or-ed with the permissions when invoking system calls as in:

     msgflg = IPC_CREAT | IPC_EXCL | 0666;
     id = msgget (key, msgflg);

Note that IPC_PRIVATE is not a flag but a special key that ensures (when the call is successful) that a new resource is created.

Use of IPC_PRIVATE does not make the resource inaccessible to other users. For this you must set the access permissions appropriately.

There is currently no way for a process to ensure exclusive access to a resource. IPC_CREAT | IPC_EXCL only ensures (on success) that a new resource was initialized. It does not imply exclusive access.

See Also : See msgget, See semget, See shmget.

1.4.2 The ctl system calls

Provides or alters the information stored in the structure that describes the resource indexed by id.

     #include <sys/msg.h>
     struct msqid_ds buf;
     err = msgctl (id, IPC_STAT, &buf);
     if (err)
             !$#%*
     else
             printf ("creator uid = %d\n", buf.msg_perm.cuid);
             ....

Commands supported by all ctl calls:

The IPC_RMID command results in immediate removal of a message queue or semaphore array. Shared memory segments however, are only destroyed upon the last detach after IPC_RMID is executed.

The semctl call provides a number of command options that allow the user to determine or set the values of the semaphores in an array.

See Also: See msgctl, See semctl, See shmctl.

1.4.3 The op system calls

Used to send or receive messages, read or alter semaphore values, attach or detach shared memory segments. The IPC_NOWAIT flag will cause the operation to fail with error EAGAIN if the process has to wait on the call.

flags : IPC_NOWAIT => return with error if a wait is required.

See Also: See msgsnd,See msgrcv,See semop,See shmat, See shmdt.