开发者

Bash/ps: get pid of a running "myscript.sh" child of a certain process

开发者 https://www.devze.com 2023-02-07 18:09 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消