Thread: Best method of terminating a program

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    18

    Best method of terminating a program

    Hello!

    I have a program which consists of N processess. One of them (the parent) has created sets of semaphores, shared memory and message queue. How to clean after this program nicely? I know i must write a function to do that and call it whenever a user sends SIGINT or other terminating signal or the process just die. And what are main types of signals that i must capture?

    Thank you!
    Last edited by kbzium; 01-10-2012 at 01:31 PM.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I would only capture SIGINT. SIGINT is used to communicate the intent of the user to shut the program down. Other signals are probably indicative of bugs.

    There isn't a lot you can safely do from within a signal handler. Really, you should just set a flag (some global variable of type sig_atomic_t), and check this flag elsewhere, and shut down within the main program logic at a safe point.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to display something before terminating the program
    By cprogrammer1980 in forum C Programming
    Replies: 1
    Last Post: 03-17-2011, 12:43 PM
  2. Terminating Program
    By millsy2000 in forum C Programming
    Replies: 11
    Last Post: 04-22-2010, 11:31 PM
  3. How can I get my program to stop terminating?
    By mklickman in forum C Programming
    Replies: 3
    Last Post: 09-19-2006, 11:06 AM
  4. Terminating a GLUT program?
    By glo in forum Game Programming
    Replies: 4
    Last Post: 07-05-2006, 02:37 AM
  5. Terminating a program
    By whisper11 in forum C++ Programming
    Replies: 1
    Last Post: 02-03-2005, 12:59 PM