Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2596
  • Last Modified:

How to get pid of child java processes

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
akshay_n_s
Asked:
akshay_n_s
  • 3
  • 2
1 Solution
 
sciuriwareCommented:
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
 
hoomanvCommented:
Why are you forking the JVM process ?
Java has eased concurrent programming by introducing Threads
0
 
akshay_n_sAuthor Commented:
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.

 
sciuriwareCommented:
That may be true but you can program against that.

;JOOP!
0
 
akshay_n_sAuthor Commented:
Actually an api that I am using for a CRM software is not thread safe...thats why...
0
 
sciuriwareCommented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now