Search code examples
bashparallel-processingpidsiblings

Getting PIDs of siblings


I'm starting several parallel bash scripts (siblings) from within another bash script (parent). How do I best get within these scripts the PIDs of the other siblings?

The parent process I can get with

ps -p $$ -o ppid --no-heading

but I could not figure out how to get it's child processes.


Solution

  • Try ps --ppid <parent-process-id> (or) pgrep -P <parent-process-id>

    From the man page of ps

    --ppid pidlist Select by parent process ID. This selects the processes with a parent process ID in pidlist. That is, it selects processes that are children of those listed in pidlist.

    For pgrep

    -P ppid,... Only match processes whose parent process ID is listed.