Find the answer to your Linux question:
Results 1 to 6 of 6
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 ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    10

    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

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    955
    The pstree command lists processes as a branching tree. To start from a particular process, use its PID as an argument.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  3. #3
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    I think that in your specific instance of the Oracle scripts firing up other scripts, killing the topmost PPID will work, but for reasons I've never really dug into, some child processes will reattach to PID 1 (init) instead of dying when the parent does. You don't want to kill that parent.

  4. #4
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    955
    Quote Originally Posted by greyhairweenie View Post
    I think that in your specific instance of the Oracle scripts firing up other scripts, killing the topmost PPID will work, but for reasons I've never really dug into, some child processes will reattach to PID 1 (init) instead of dying when the parent does. You don't want to kill that parent.
    From my reading, that's the way orphaned processes are supposed to behave. I think that when an orphan just dies, it must be because it was linked to its parent in some way, probably with a pipe.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  5. #5
    Just Joined!
    Join Date
    Apr 2011
    Posts
    1
    In Redhat, at least, there is the --ppid option. So the command

    ps --ppid <parent_process_id>

    will list the child processes.

  6. #6
    Just Joined!
    Join Date
    Sep 2008
    Location
    Tampa Bay Area,FL
    Posts
    9

    Re: process children

    If you are working in the Bourne shell, try:
    ps --forest -ef
    which will give you a better view of parent-child relationships among the processes.
    This may not work on your implementation.
    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...