• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to stop zombie processes?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic