Solved

How to get pid of child java processes

Posted on 2006-11-07
9
2,385 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
Comment Utility
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
Comment Utility
Why are you forking the JVM process ?
Java has eased concurrent programming by introducing Threads
0
 

Author Comment

by:akshay_n_s
Comment Utility
Threads have their limitations, like if any one of them fails then it may cause others to get failed...
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
That may be true but you can program against that.

;JOOP!
0
 

Author Comment

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

Expert Comment

by:sciuriware
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now