How do you kill all child processes without killing the parent

前端 未结 2 1653
夕颜
夕颜 2021-01-15 06:25

I have a script which runs a background process at the beginning, then towards the end needs to stop that background process and its children, THEN do some other tasks etc t

2条回答
  •  一个人的身影
    2021-01-15 07:18

    You need to capture the value of $! (the child PID) right after

    /some_process_with_child_processes &
    pid=$!
    ./do_stuff
    kill $pid
    ./do_other_stuff
    

提交回复
热议问题