LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command to find parent and child process? (https://www.linuxquestions.org/questions/linux-newbie-8/command-to-find-parent-and-child-process-876297/)

newbie01.linux 04-21-2011 04:52 AM

Command to find parent and child process?
 
Hi,

I have a script that calls other scripts/commands which may or may not spawn other process.

From my understanding, when I do a ps -ef, the highest numbered process ID is supposed to be the parent ID of all the other related child processes, is this correct?

In most or all circumstances, I do a ps -ef | grep <processid> of my script and anything that spawns off that process IDs I assumed are the child processes of my script. If I want to terminate my script and all other child processes, then I kill the parent ID which is the highest numbered PID and this will subsequently kill all other child process IDs, is this correct?

Now, my question is whether there is any quick way of showing what are the child processes of a parent ID instead of what am currently doing now which is visually checking which one is the parent ID and "assuming" that the highest numbered PID is the parent ID of all the other processes.

Below is a sample output of running ps -ef | grep exp | grep -v grep. I assume from the output below that the parent process/ID is PID 11322, is that correct?

Any advice or suggestion will be much appreciated. Thanks in advance.

Code:

oracle  11154 11153  0 21:20 ?        00:00:00 /bin/sh -c (. ~oracle/.profile; /bin/ksh /usr/local/oracle/scripts/expdp_o
oracle  11155 11154  0 21:20 ?        00:00:00 /bin/sh -c (. ~oracle/.profile; /bin/ksh /usr/local/oracle/scripts/expdp_o
oracle  11190 11155  0 21:20 ?        00:00:00 /bin/ksh /usr/local/oracle/scripts/expdp_schema.ksh dev01
oracle  11322 11190  0 21:20 ?        00:00:00 expdp


ozanbaba 04-21-2011 05:11 AM

how about this;
Code:

ps --ppid
You can get your own pid with $$.

jadrevenge 04-21-2011 05:33 AM

if you're on linux "pstree -p <processid>" or "ps --ppid <processid>" might well give you what you want.

on solaris you can do a "ptree" ...

on the other hand if all you want to do is kill of all sub processes you might be as well off using "pkill -P <processid>" which appears to be the same on both platforms


All times are GMT -5. The time now is 08:51 PM.