#include #include #include #include #include #include #include #include #ifndef CLONE_NEWPID # define CLONE_NEWPID 0x20000000 #endif int child(void *arg) { if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0)) { perror("prctl"); return -1; } sleep(3); printf("I should have gone with my parent\n"); return -1; } pid_t clonens(int (*fn)(void *), void *arg, int flags) { long stack_size = sysconf(_SC_PAGESIZE); void *stack = alloca(stack_size) + stack_size; return clone(fn, stack, flags | SIGCHLD, arg); } int main(int argc, char *argv[]) { pid_t pid; pid = clonens(child, NULL, CLONE_NEWNS|CLONE_NEWPID); if (pid < 0) { perror("clone"); return -1; } /* let the child to be ready, ugly but simple code */ sleep(1); return 0; }