Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to get pid of child java processes

Posted on 2006-11-07
9
Medium Priority
?
2,550 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
9 Comments
 
LVL 24

Accepted Solution

by:
sciuriware earned 1500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

610 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