LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-27-2009, 04:52 PM   #1
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Rep: Reputation: 16
Question Extracting a Specific Child's Process ID


All:

I have a shell script which runs a java program. Inside this java program I run a java simulation.

So the broad picture is:
Run Script -> Script initiates a java program -> in this program, there is another java program initiated

I would like to get the process id of the last one. Is it possible?

I would be more than pleased if somebody could help!
 
Old 03-27-2009, 05:11 PM   #2
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
Have you tried top, or ps -aux or ps -U username

These commands will give you the process ID of programs/scripts and
IDs of programs/commands started from scripts as well.
 
Old 03-27-2009, 05:15 PM   #3
synss
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian, Gentoo, Mac OS X
Posts: 137

Rep: Reputation: 22
ps can display the parent process ID, so that if you know how deep you need to go in the tree, and that is apparently the case, you should be able to locate the parent ID with ps and grep and then look for its children in the hierarchy by sed'ing the parent process ID (PPID).

Example:
Code:
PARENT=java_parent
ps -f -u $UID | awk '/$PARENT/ {print $2}'
should give you the process ID of the parent; another run of ps -f, searching for the PPID in the proper column will allow you to find its children. Once more and you are done.
 
Old 03-27-2009, 05:43 PM   #4
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Original Poster
Rep: Reputation: 16
Thanks a lot dv502 and synss.

It worked!
 
Old 03-27-2009, 09:27 PM   #5
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
Glad to help...
 
  


Reply

Tags
child, extract, id, process


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Killing a Specific Process the_satsuma_man Programming 4 03-11-2009 09:42 PM
kill specific process fj8283888 Linux - General 6 05-31-2007 06:28 AM
get info about a specific process hfawzy Programming 4 01-31-2007 01:11 PM
Extracting Process State in Linux kamal_h_mehta Programming 2 10-07-2005 01:13 PM
Extracting a specific line from an ASCII file heyyou Programming 7 03-21-2005 04:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration