How to get child process from parent process

前端 未结 9 760
清歌不尽
清歌不尽 2020-11-30 23:05

Is it possible to get the child process id from parent process id in shell script?

I have a file to execute using shell script, which leads to a new process

9条回答
  •  悲&欢浪女
    2020-11-30 23:21

    I'v written a scrpit to get all child process pids of a parent process. Here is the code.Hope it helps.

    function getcpid() {
        cpids=`pgrep -P $1|xargs`
    #    echo "cpids=$cpids"
        for cpid in $cpids;
        do
            echo "$cpid"
            getcpid $cpid
        done
    }
    
    getcpid $1
    

提交回复
热议问题