LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Extracting a Specific Child's Process ID (https://www.linuxquestions.org/questions/linux-newbie-8/extracting-a-specific-child%27s-process-id-714938/)

senthilmuthiah 03-27-2009 04:52 PM

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!

dv502 03-27-2009 05:11 PM

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.

synss 03-27-2009 05:15 PM

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.

senthilmuthiah 03-27-2009 05:43 PM

Thanks a lot dv502 and synss.

It worked! :D

dv502 03-27-2009 09:27 PM

Glad to help...


All times are GMT -5. The time now is 01:59 AM.