The shmctl ( SHared Memory ConTroL ) call returns information about a shared memory segment and can modify it.
- The first parameter is a shared memory segment identifier.
- To obtain information about a shared memory segment, pass
IPC_STAT as the second argument and a pointer to a struct shmid_ds.
- To remove a segment, pass IPC_RMID as the second argument, and pass NULL as the third argument. The segment is removed when the last process that has attached it finally detaches it.
- Each shared memory segment should be explicitly deallocated using shmctl when you are finished with it, to avoid violating the system wide limit on the total number of shared memory segments. Invoking exit and exec detaches memory segments but does not deallocate them.
- The following http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/shm.cprogram (see Fig. 6.1.5) illustrates the use of shared memory.
Figure 6.1:
Exercise Shared Memory
|
$ ipcs -m
$ ipcrm shm 1627649