我有一个子进程在前台运行,他的父亲已经退出。
如果父进程已经退出,则proc/$pid/stat
文件不再包含父进程 pid,并且显示 1 而不是原始父进程进程 pid
linux$cat /proc/6267/stat
6267 (test3.sh) S 1 6265 ......
# ^
# |
# I expected to get the origin parent pid but I get 1
为了快速重现此行为,我们可以使用以下脚本
测试2.sh
#!/bin/sh
echo "test2=$$"
./test3.sh &
测试3.sh
#!/bin/sh
echo "test3=$$"
sleep 1000
执行:
linux$ ./test2.sh
test2=6318
test3=6319
linux$ ps aux | grep test
6319 root 1484 S {test3.sh} /bin/sh ./test3.sh
linux$ cat /proc/6319/stat
6319 (test3.sh) S 1 6318 2138 34816 6.......