shmctl(2) is used to alter the permissions and other characteristics of a shared memory segment. The cmd argument is one of following control commands.
Lock the specified shared memory segment in memory. The process must have the effective ID of superuser to perform this command.
Unlock the shared memory segment. The process must have the effective ID of superuser to perform this command.
Return the status information contained in the control structure and place it in the buffer pointed to by buf. The process must have read permission on the segment to perform this command.
Set the effective user and group identification and access permissions. The process must have an effective ID of owner, creator or superuser to perform this command.
Remove the shared memory segment. The process must have an effective ID of owner, creator, or superuser to perform this command.
The following code illustrates shmctl(2).
#include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> ... int cmd; /* command code for shmctl() */ int shmid; /* segment ID */ struct shmid_ds shmid_ds; /* shared memory data structure to hold results */ ... shmid = ... cmd = ... if ((rtrn = shmctl(shmid, cmd, shmid_ds)) == –1) { perror("shmctl: shmctl failed"); exit(1); ...