Answers for "write a c program to avoid zombie process by forking twice"

0

write a c program to avoid zombie process by forking twice

#include<stdio.h>#include <sys/wait.h>#include<errno.h>#include<stdlib.h>int main(){pid_t pid;if ((pid = fork()) < 0){printf("fork error");}else if (pid == 0){ /* first child */if ((pid = fork()) < 0)printf("fork error");else if (pid > 0)exit(0);sleep(2);printf("second child, parent pid = %d\n", getppid()); exit(0);}if (waitpid(pid, NULL, 0) != pid) /* wait for first child */printf("waitpid error");exit(0);}
Posted by: Guest on February-15-2021

Code answers related to "write a c program to avoid zombie process by forking twice"

Browse Popular Code Answers by Language