I have a program that creates and uses a shared memory segment. I am trying to find out how to detach and delete this shared memory segment when I hit crtl-C, and I still need the process to terminate.
shmdt() and shmctl() have variables that are local to the main passed to them
(shared and shmid)
Code:
//Prototype
void leave(int sig);
//part of code trying to use signal handling
if(signal(SIGINT, leave))
{
//Deallocate shared memory segment
shmdt(shared);
//remove shared memory segment
shmctl(shmid, IPC_RMID, NULL);
}
//leave declaration
void leave(int sig)
{
sleep(10);
}