Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to stop zombie processes?  RSS feed

 
Sa Pa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From my servlet I am spawning off a child process to run an executable. The problem is that sometimes the user presses "stop" on their browser, which then causes the servlet's thread to stop for that connection. The end result is that I'm left with a zombie process on my unix system.

Does anybody have a work around for this? I don't think it's restricted to just servlets; I think I encountered this in old CGI days as well.
 
Roger Nelson
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometime back I had come across a similar requirement to execute a unix script via servlet and implementation was along the folowing lines.
================================
runObj = Runtime.getRuntime();
proc = runObj.exec(unixscript.sh);
int exitcode = proc.waitFor();
================================

If I understand it correctly the stop applied on the browser will only terminate the browsers ability to display the response from the servlet.
while the servlet thread spawned will continue it execution in the container.

Is the zombie process created due to something going wrong in the interaction between the servlet and the unix executable?
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if this happens to be Solaris, you can stop this zombie with
"preap <pid>" as root as of Solaris 9 and later.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to do with killing threads, but ...

Is that really what happens when the user hits "stop"? I only know the little web server I wrote, and it gets no signal from the browser that anything has happened. Instead it gets an IO exception when it tries to write the response because the socket has been terminated by the client.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
Instead it gets an IO exception when it tries to write the response because the socket has been terminated by the client.


Yep, that's all, and so really it's got everything to do with those zombie processes. Make sure you call waitFor() in a finally block, with the corresponding "try" encompassing any attempts to write output back to the browser; that way the process will be reaped even if the service method is aborted. Really just standard good programming practice -- no "trick" involved.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!