I am trying to write a C++ program to delete the shared memory segments. I know it can be done from cmd prompt using
ipcs -m | awk '{ print $2 }' | xargs ipcrm -m
But I am trying to do it using C++ so that I create a shared memory garbage collector.
The idea is to delete shared memory segments that are not attached to any process( nattach ==0) or the status == NULL
I finally have the the answer to my own question. It can be done using shmctl flags.
shmctl(0,SHM_INFO,&shm_info);gives number of segments currently present.shmctl(i , SHM_STAT , &shm_segment)gives the segment idit can also be accessed by
shm_segment.shm_id