runtime exec leaving <defunct> processes in unix

I'm calling runtime.exec to call a .sh script in unix.. this is done in a loop..  i am seeing a <defunct> proceess created in unix every iteration!  this will not do..  any idea how to have runtime.exec clean up after istelf?  

the .sh script is only checking to see in another process is running..  ( ps -a | mlcserv | wc -l )
xjeffkAsked:
Who is Participating?
 
yorenConnect With a Mentor Commented:
xjeffk,

Glad it worked for you. You had the right thinking when you said "clean up after itself." The issue is that many versions (maybe all?) of UNIX don't try to clean up child processes until the parent specifically waits for them to complete. If you want to kill a process and not leave a <defunct> child, you can try destroy() followed by waitFor() (I haven't tried this but it should work).

Leave another comment if you have more related questions.

Yuval
0
 
yorenCommented:
Try Process.waitFor() and see if that helps.
0
 
xjeffkAuthor Commented:
Yoren - that seems to work!  how does it have a handle to the thread, but destroy does nothing?
0
 
xjeffkAuthor Commented:
indeed.   it's solaris, and the waitFor did it..  just calling destroy without waitFor did not..

well, thanks..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.