Last active
May 15, 2016 19:42
-
-
Save gg7/cadcdbae9d895a7639a863c2a6188542 to your computer and use it in GitHub Desktop.
leaking orphaned processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@u1404:~# cat /etc/init/orph.conf | |
description "orphaned process / process group test" | |
respawn | |
script | |
sleep 9999 & | |
sleep 4444 | |
end script | |
root@u1404:~# start orph | |
orph start/running, process 3269 | |
root@u1404:~# ps faxo pid,ppid,pgid,sid,tname,tpgid,uid,cmd | tee >(head -n1 >&2) | grep -v grep | grep -C1 sleep | |
PID PPID PGID SID TTY TPGID UID CMD | |
3269 1 3269 3269 ? -1 0 /bin/sh -e /proc/self/fd/9 | |
3271 3269 3269 3269 ? -1 0 \_ sleep 9999 | |
3272 3269 3269 3269 ? -1 0 \_ sleep 4444 | |
# All processes are in the same process group (3269). Let's trace their signals and stop the upstart job. | |
root@u1404:~# for p in $(pidof sleep); do strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" & done | |
[1] 3282 | |
[2] 3284 | |
root@u1404:~# 3271: Process 3271 attached | |
3272: Process 3272 attached | |
# "stop orph" will terminate both sleep processes: | |
root@u1404:~# stop orph | |
3272: --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} --- | |
3271: --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} --- | |
3272: +++ killed by SIGTERM +++ | |
3271: +++ killed by SIGTERM +++ | |
orph stop/waiting | |
[1]- Done strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" | |
[2]+ Done strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If the main process gets killed or dies abnormally the background process gets adopted by init and "leaks": | |
root@u1404:~# start orph | |
orph start/running, process 3315 | |
root@u1404:~# ps faxo pid,ppid,pgid,sid,tname,tpgid,uid,cmd | tee >(head -n1 >&2) | grep -v grep | grep -C1 sleep | |
PID PPID PGID SID TTY TPGID UID CMD | |
3315 1 3315 3315 ? -1 0 /bin/sh -e /proc/self/fd/9 | |
3317 3315 3315 3315 ? -1 0 \_ sleep 9999 | |
3318 3315 3315 3315 ? -1 0 \_ sleep 4444 | |
root@u1404:~# for p in $(pidof sleep); do strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" & done | |
[1] 3443 | |
[2] 3445 | |
root@u1404:~# 3317: Process 3317 attached | |
3318: Process 3318 attached | |
root@u1404:~# kill 3318 | |
3318: --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1991, si_uid=0} --- | |
3318: +++ killed by SIGTERM +++ | |
[1]- Done strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" | |
root@u1404:~# ps faxo pid,ppid,pgid,sid,tname,tpgid,uid,cmd | tee >(head -n1 >&2) | grep -v grep | grep -C1 sleep | |
PID PPID PGID SID TTY TPGID UID CMD | |
1314 1 1314 1314 tty1 1314 0 /sbin/getty -8 38400 tty1 | |
3317 1 3315 3315 ? -1 0 sleep 9999 | |
3454 1 3454 3454 ? -1 0 /bin/sh -e /proc/self/fd/9 | |
3456 3454 3454 3454 ? -1 0 \_ sleep 9999 | |
3457 3454 3454 3454 ? -1 0 \_ sleep 4444 | |
Raw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@u1604:~# cat /etc/systemd/system/orph.service | |
[Unit] | |
Description=orphaned process / process group test | |
[Service] | |
Restart=on-failure | |
ExecStart=/bin/sh -ec 'sleep 9999 & sleep 4444' | |
root@u1604:~# systemctl start orph.service | |
root@u1604:~# systemctl status orph.service | |
* orph.service - orphaned process / process group test | |
Loaded: loaded (/etc/systemd/system/orph.service; static; vendor preset: enabled) | |
Active: active (running) since Sun 2016-05-15 19:29:27 UTC; 4s ago | |
Main PID: 14847 (sh) | |
Tasks: 3 (limit: 512) | |
CGroup: /system.slice/orph.service | |
|-14847 /bin/sh -ec sleep 9999 & sleep 4444 | |
|-14849 sleep 9999 | |
`-14850 sleep 4444 | |
May 15 19:29:27 u1604 systemd[1]: Started orphaned process / process group test. | |
root@u1604:~# ps faxo pid,ppid,pgid,sid,tname,tpgid,uid,cmd | tee >(head -n1 >&2) | grep -v grep | grep -C1 sleep | |
PID PPID PGID SID TTY TPGID UID CMD | |
1398 1 1398 1398 ? -1 0 /sbin/dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0 | |
14847 1 14847 14847 ? -1 0 /bin/sh -ec sleep 9999 & sleep 4444 | |
14849 14847 14847 14847 ? -1 0 \_ sleep 9999 | |
14850 14847 14847 14847 ? -1 0 \_ sleep 4444 | |
root@u1604:~# for p in $(pidof sleep); do strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" & done | |
[1] 14861 | |
[2] 14863 | |
root@u1604:~# 14850: strace: Process 14850 attached | |
14849: strace: Process 14849 attached | |
root@u1604:~# service orph stop | |
14850: --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} --- | |
14850: +++ killed by SIGTERM +++ | |
14849: --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} --- | |
14849: +++ killed by SIGTERM +++ | |
[1]- Done strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" | |
[2]+ Done strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@u1604:~# systemctl start orph.service | |
root@u1604:~# ps faxo pid,ppid,pgid,sid,tname,tpgid,uid,cmd | tee >(head -n1 >&2) | grep -v grep | grep -C1 sleep | |
PID PPID PGID SID TTY TPGID UID CMD | |
1398 1 1398 1398 ? -1 0 /sbin/dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0 | |
14895 1 14895 14895 ? -1 0 /bin/sh -ec sleep 9999 & sleep 4444 | |
14897 14895 14895 14895 ? -1 0 \_ sleep 9999 | |
14898 14895 14895 14895 ? -1 0 \_ sleep 4444 | |
root@u1604:~# for p in $(pidof sleep); do strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" & done | |
[1] 14907 | |
[2] 14909 | |
root@u1604:~# 14898: strace: Process 14898 attached | |
14897: strace: Process 14897 attached | |
root@u1604:~# kill -9 14898 | |
root@u1604:~# 14898: +++ killed by SIGKILL +++ | |
14897: --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} --- | |
14897: +++ killed by SIGTERM +++ | |
[1]- Done strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" | |
[2]+ Done strace -f -e trace=signal -p "$p" 2>&1 | sed -e "s/^/$p: /" | |
root@u1604:~# ps faxo pid,ppid,pgid,sid,tname,tpgid,uid,cmd | tee >(head -n1 >&2) | grep -v grep | grep -C1 sleep | |
PID PPID PGID SID TTY TPGID UID CMD | |
1398 1 1398 1398 ? -1 0 /sbin/dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0 | |
14914 1 14914 14914 ? -1 0 /bin/sh -ec sleep 9999 & sleep 4444 | |
14916 14914 14914 14914 ? -1 0 \_ sleep 9999 | |
14917 14914 14914 14914 ? -1 0 \_ sleep 4444 | |
root@u1604:~# systemctl status orph.service | |
* orph.service - orphaned process / process group test | |
Loaded: loaded (/etc/systemd/system/orph.service; static; vendor preset: enabled) | |
Active: active (running) since Sun 2016-05-15 19:33:21 UTC; 1min 0s ago | |
Main PID: 14914 (sh) | |
Tasks: 3 (limit: 512) | |
CGroup: /system.slice/orph.service | |
|-14914 /bin/sh -ec sleep 9999 & sleep 4444 | |
|-14916 sleep 9999 | |
`-14917 sleep 4444 | |
May 15 19:33:21 u1604 systemd[1]: Started orphaned process / process group test. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment