Search code examples
macosbashpid

Get the pids launched by a command


I am running Mac OS X Yosemite.

I am trying to return the PIDs started by a command launch using a background process style. (myCommand &)

To get them I found $! which return the PID of the last running process.

Or something like pgrep -f "elm" which return all the pid with elm in the command line.

I am wondering if there is a another way to get the PIDs started by a command. Because, I have some programs starting severals processes and $! only return the last one and using pgrep could return PID started by another command that the one I want to target.

Edit:

How to get the list of the PIDs started by a command ?

Edit 2:

State of the PIDs

Edit 3:

Parents


Solution

  • Use pidof.

    pidof command
    

    OR

    pidof program
    

    OR

    pidof [options] program1 program2 ... programN