Link to home
Start Free TrialLog in
Avatar of souvik_mss
souvik_mss

asked on

Unix process termination

Before asking the question I am describing the scenario
I have a child process that I have created from the parent by using fork. Now I have registered a signal handler for my user defined signal in the child process. The child process after doing something is waiting in infinite loop. After something I fire the signal from the parent process and in the signalk handler I have a call to exit to terminate the child process. It works fine. But consider the following scenario also.
   The same child process is waiting for some input from standard input device(keyboard) without waiting in infinite loop. And sometime I supplied the input and it will encouter the terminating brace and the child process will terminate.
  Now my question is Is there any difference between these two kind of termination.
  If u need any clarification regarding this feel free to ask me.
  Waiting for help or any link where I can have some discussion on this topic,
 Thanking u in advance  
                    Souvik
Avatar of jlevie
jlevie

Not really as fas as the child is concerned. In both cases the child will have exited, presumably in an orderly manner. However, it migh make a difference to the parent. In the case of sending a signal from the parent, the parent has reason to believe that the child will exit. On the other hand if the child exits on it's own the parent process won't necessarily know that.
Avatar of souvik_mss

ASKER

I want to know about the system cleanup and the open file descriptor of the child when terminated by signal. I am not interested about parent process and even if any one get interested, she/he can call wait on its child's pid. My point of interest is that when the child process terminates by exit call inside signal handler then will the destructor of the objects created will be called or suppose the socket(file descriptor) by which that the process was communicating with some other process will get closed. My question is will the memory dynamically locked will be freed.
ASKER CERTIFIED SOLUTION
Avatar of chris_calabrese
chris_calabrese

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As ususal chris is quite correct.
Cleanup is identical in both cases, *unless* you have code registered with atexit() which cleans up SYSV IPC resources (the Unix kernel always cleans up everything except SYSV IPC resources for you).  

If you opened a scratch file with something like mktemp(), of course you would need to clean them up yourself (and hence calling exit() would allow an atexit()-registered handler to do that while a fatal signal would not).   But tmpfile() would have been better in any case - no file is left lying around because it's deleted before the tmpfile() function returns.
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by chris_calabrese

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster (I don't work here, I'm just an Expert :-)
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange