- 论坛徽章:
- 0
|
执行下面的脚本:
- ( echo "后台进程再开启子进程"; sleep 99s; ) &
- myPID=$!
- ps -ef | grep $myPID | grep -v grep
- ps -ef | grep sleep | grep -v grep
- kill -9 $myPID
- ps -ef | grep sleep | grep -v grep
复制代码
输出:
- $ ( echo "后台进程再开启子进程"; sleep 99s; ) &
- [1] 15348
- 后台进程再开启子进程
- $ myPID=$!
- $ ps -ef | grep $myPID | grep -v grep
- search 15348 17134 0 10:40 pts/6 00:00:00 /bin/bash
- search 15349 15348 0 10:40 pts/6 00:00:00 sleep 99s
- $ ps -ef | grep sleep | grep -v grep
- search 15349 15348 0 10:40 pts/6 00:00:00 sleep 99s
- $ kill -9 $myPID
- [1]+ Killed ( echo "后台进程再开启子进程"; sleep 99s )
- $ ps -ef | grep sleep | grep -v grep
- search 15349 1 0 10:40 pts/6 00:00:00 sleep 99s
复制代码
我期望执行“kill -9 $myPID”杀死父进程时,子进程“sleep 99s”也被杀死,而不是被1进程托管
|
|