Bash/ps: get pid of a running "myscript.sh" child of a certain process
in bash I need to get the pid of a running process whose I know name and parent pid.
In ps' manual I read you can select processes using such arguments:--ppid <pidlist>
and
-C <cmdlist>
So, in order to get the pid of running "myscript.sh" child of $parentpid, I tried:
ps -C myscript.sh --ppid $parentpid -o pid --no-headers
but I got all the children processes of $parentpid. The -C argument seems to be ignored also if I swap it with the other one.
Any help, expecially avoiding sed and开发者_运维知识库 grep and the like? Thank you!
Give this a try:
pgrep -P $parentpid '^myscript.sh$'
Also see Process Management.
精彩评论