Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNIX zombie/defunct processes 1

Status
Not open for further replies.

sultanap

Programmer
Jan 7, 2000
3
GB
Development environment is<br>
HPUX 10.20, TCL version 7.3.<br>
<br>
Within our application we need to fork off a new process and run it in the background. To achieve this, within our TCL script procedure, we use 'exec newProcess &' command which forks off a child process running 'newProcess' in the background.<br>
<br>
Unfortunately when the child process terminates (normally) a defunct/zombie process is left utilising CPU.<br>
<br>
Has anyone come across this problem and have a resolution.<br>
<br>
Thanks
 
When you fire off the process, exec returns the PID, so try something like this:<br>
<br>
set tmpPID [exec newProcess &]<br>
<br>
then, as part of your cleanup, include:<br>
<br>
exec /bin/kill $tmpPID<br>
<br>
which should kill newProcess.<br>
<br>
Good luck!
 
Thanks for responding Mr Mango. <br>
<br>
I have already tried this and not even 'root' authority can kill off the defunct process. The only way to get rid of the process is to either:<br>
1. Terminate the Parent Process <br>
2. To issue another exec command in the foreground from the parent after the child has terminated leaving the defunct process.<br>
<br>
Option two is impractical as I have no idea when the child process has ended (without an elaborate signal handling solution) to issue the second foreground exec.<br>
<br>
<br>

 
Dear Sir:<br>I have written a c code which fork/execs.&nbsp;&nbsp;There are many ways the parent can fail.&nbsp;&nbsp;I've had to trap various death signals and from the signal handlers take special care to delete the child process, otherwise the child ends up in a &quot;zombie&quot; state.&nbsp;&nbsp;I expect that this information is tangential and useless to you.<br>
 
Dear Sir,<br><br>Thanks for your interesting posting.<br>The way we got round this problem was to write a C routine which eventually called the 'system' C API and added it to<br>out TCL interpreter.<br>From your posting I gather that your solution is more complex/complete as you are forking and trapping signals from the child process.<br>As the zombie process is left when you run a TCL exec command in the background and were not really interested in the how the child died we opted for the easier solution.<br>This was a quick win solution which had to be implemented within a week.&nbsp;&nbsp;&nbsp;<br>The long term solution would be to write and build into the interpreter a routine similar to the one you wrote.<br><br>Thanks for your posting<br>
 
Here's a (non-portable) workaround that gives the desired behaviour on systems with procfs (usually /proc).&nbsp;&nbsp;When a process becomes a zombie the directory entry in /proc for the process, or one of the files in the directory, changes somehow.&nbsp;&nbsp;The exact change depends on the system (check system man pages or experiment).&nbsp;&nbsp;On Solaris the process directory ceases to be readable, so:<br><FONT FACE=monospace><br>&nbsp;&nbsp;# open process via pipe, starts in background<br>&nbsp;&nbsp;set p [open &quot;¦ my_background_job&quot; &quot;w&quot;]<br><br>&nbsp;&nbsp;# store process id<br>&nbsp;&nbsp;set id [pid $p]<br><br>&nbsp;&nbsp;# wait for zombie<br>&nbsp;&nbsp;while {[file readable /proc/$id]} {<br>&nbsp;&nbsp;&nbsp;&nbsp;# do background processing<br>&nbsp;&nbsp;&nbsp;&nbsp;# ...<br>&nbsp;&nbsp;&nbsp;&nbsp;# take a break<br>&nbsp;&nbsp;&nbsp;&nbsp;after 500<br>&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;# release pipe resources (reaps zombie)<br>&nbsp;&nbsp;close $p<br></font><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top