I have a child process running in foreground and his father is already exited.
the proc/$pid/stat
file does not contain any more the parent pid if the parent is already exited and it display 1 instead of the origin parent pid
linux$cat /proc/6267/stat
6267 (test3.sh) S 1 6265 ......
# ^
# |
# I expected to get the origin parent pid but I get 1
To reproduce this behaviour quickly we can use the following scripts
test2.sh
#!/bin/sh
echo "test2=$$"
./test3.sh &
test3.sh
#!/bin/sh
echo "test3=$$"
sleep 1000
execution:
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.......
I don't think you can know the parent of a process after the (parent) has finished executing. But maybe you can have another program running which monitors your original program and maintains a log file or something. And orphaned processes are of course, adopted by init.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With