Skip to content

Instantly share code, notes, and snippets.

@kesor
Last active January 24, 2019 20:31
Show Gist options
  • Save kesor/5374472b332fa891a3e3 to your computer and use it in GitHub Desktop.
Save kesor/5374472b332fa891a3e3 to your computer and use it in GitHub Desktop.
root@89de118f2aa3:~# ps -ef ; date ; nohup ./zombie & ; sleep 2 ; ps -ef ; sleep 65 ; date ; ps -ef
bash: syntax error near unexpected token `;'
root@89de118f2aa3:~# ps -ef ; date ; (nohup ./zombie &) ; sleep 2 ; ps -ef ; sleep 65 ; date ; ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 16:41 ? 00:00:00 /bin/bash
root 364 1 0 16:47 ? 00:00:00 ps -ef
Wed May 20 16:47:37 UTC 2015
nohup: appending output to 'nohup.out'
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 16:41 ? 00:00:00 /bin/bash
root 367 1 0 16:47 ? 00:00:00 ./zombie
root 369 367 0 16:47 ? 00:00:00 [zombie] <defunct>
root 370 1 0 16:47 ? 00:00:00 ps -ef
Wed May 20 16:48:44 UTC 2015
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 16:41 ? 00:00:00 /bin/bash
root 373 1 0 16:48 ? 00:00:00 ps -ef
root@89de118f2aa3:~#
docker@testbox:~$ date ; ps -ef | grep zombie
Wed May 20 16:48:03 UTC 2015
9281 root ./zombie
9283 root [zombie]
9297 docker grep zombie
docker@testbox:~$ date ; ps -ef | grep zombie
Wed May 20 16:48:56 UTC 2015
9312 docker grep zombie
docker@testbox:~$ uptime
16:49:42 up 1 day, 20:59, 2 users, load average: 0.00, 0.01, 0.04
// can run this zombie process as the "sole" process inside of a container
// (bash might be reaping children)
// even though 30 zombies don't have parents, after 5 minutes the container
// exist and there are no zombies in sight at the host level process tables
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main ()
{
int i;
pid_t parent_pid;
pid_t child_pid;
// spawn 30 zombie grand children
for (i=30; i>0; i--) {
parent_pid = fork();
if (parent_pid > 0) {
// run a child
child_pid = fork ();
if (child_pid > 0) {
// child
sleep (60);
}
else {
// parent
exit (0);
}
}
else {
// grand parent (actual exec) just sleeps for 5 min
// doesn't waitpid or reaps anything
if (i == 1) {
sleep (300);
}
}
}
return 0;
}
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main ()
{
pid_t child_pid;
child_pid = fork ();
if (child_pid > 0) {
sleep (60);
}
else {
exit (0);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment