I have created an application that uses shared memory and child processes. When I want the program to close, I use my function 'controlledEnd' to kill any remaining child processes and destroy the shared memory but it seems that the code in the function does not get ran/does not complete and the print statements are never printed.
/*
controlledEnd
This function safely exits the program ensuring there are no
memory leaks and that the memory segment is freed.
The function takes 1 parameter
-pid_t segmentID
The segmentID of the shared memory
*/
void controlledEnd(pid_t segmentID){
/*Kills all child processes*/
if((int)kill(0, SIGKILL)==0){
printf("All jobs successfully killed");
}
/*Logs an error if processes were not successfully killed*/
else{
logError("Any", "Could not kill processes on exit");
perror("Could not deallocate memory on exit");
}
/*Frees the segment of shared memory used for the queue*/
if((int)shmctl(segmentID, IPC_RMID, 0)==0){
printf("Memory successfully deallocated");
}
/*Logs an error if the memory was not deallocated successfully*/
else{
logError("Either", "Could not deallocate memory on exit");
perror("Could not deallocate memory on exit");
}
fflush(stdout);
exit(0);
}
Any idea as to why my shared memory segment isn't being destroyed properly?