This is used for performing certain control operations on the specified shared memory segment. Here is its syntax:
int shmctl(int shidtr, int cmd, struct shmid_ds *buf);
Here, we have to address the following:
- shidtr: Represents the identifier of the shared memory segment.
- cmd: This can have any of the following constants:
- IPC_STAT: This copies the content of the shmid_ds data structure associated with the shared memory segment represented by shidtr into the structure that's pointed to by buf
- IPC_SET: This writes the content of the structure that's pointed to by buf into the shmid_ds data structure, which is associated with the memory segment that's represented by shidtr
- IPC_RMID: This removes the shared memory identifier that's specified by shidtr from the system and destroys the shared memory segment and shmid_ds data structure associated with it
- buf: This is a pointer to a shmid_ds structure.
If successfully executed, the function returns 0, otherwise it returns -1.