SYSTEM CALL: shmctl(); PROTOTYPE: int shmctl ( int shmqid, int cmd, struct shmid_ds *buf ); RETURNS: 0 on success -1 on error: errno = EACCES (No read permission and cmd is IPC_STAT) EFAULT (Address pointed to by buf is invalid with IPC_SET and IPC_STAT commands) EIDRM (Segment was removed during retrieval) EINVAL (shmqid invalid) EPERM (IPC_SET or IPC_RMID command was issued, but calling process does not have write (alter) access to the segment) NOTES:
Retrieves the shmid_ds structure for a segment, and stores it in the address of the buf argument
Sets the value of the ipc_perm member of the shmid_ds structure for a segment. Takes the values from the buf argument.
Marks a segment for removal.
The IPC_RMID command doesn't actually remove a segment from the kernel. Rather, it marks the segment for removal. The actual removal itself occurs when the last process currently attached to the segment has properly detached it. Of course, if no processes are currently attached to the segment, the removal seems immediate.
To properly detach a shared memory segment, a process calls the shmdt system call.