Solved

How to get pid of child java processes

Posted on 2006-11-07
9
2,428 Views
Last Modified: 2008-01-09
Hi

I am working on jdk 1.3, sun solaris OS....

I use a shell script (using 'nohup') to fork a Java process, which in turn forks more than 2 java processes. I want to get pids of all newly generated child process.

My application has a behaviour that child processes terminate after completing their jobs...And parent Java process forks the child processes again whenever required...

So, everytime I want fresh pids of the child processes

Note: After executing the shell script (in background), I use to close the terminal window.

-------------------------

Actually I want to kill child processes automatically, if I parent Java process found them hang for some reason. I know that 'Process' class has a functionality to kill the child processes, but I found that many times it gets fail due to unknown reasons. So, I want to kill such child processes using a 'kill -9' command using shell script...
0
Comment
Question by:akshay_n_s
  • 3
  • 2
9 Comments
 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 17895968
There's no platform oriented service like this in JAVA.
You must tether (spawn with input and output controlled) ps to find out your PID and that of the children.
Then spawn 'kill'.

;JOOP!
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17900407
Why are you forking the JVM process ?
Java has eased concurrent programming by introducing Threads
0
 

Author Comment

by:akshay_n_s
ID: 17906578
Threads have their limitations, like if any one of them fails then it may cause others to get failed...
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 24

Expert Comment

by:sciuriware
ID: 17908372
That may be true but you can program against that.

;JOOP!
0
 

Author Comment

by:akshay_n_s
ID: 17912502
Actually an api that I am using for a CRM software is not thread safe...thats why...
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 18221510
I insist that 'ps' should be spawned to find out the PID of any process.
The processes can be 'identified' by their commandline (using "ps -f" or "ps -ef").

;JOOP!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 196
more than one jdk and one jre 1 43
String array comparison 4 34
mysql jsp example issue 32 38
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question