Solved

How to get pid of child java processes

Posted on 2006-11-07
9
2,486 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 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
Industry Leaders: 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!

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

726 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