if (fork() == 0) for(;;) sleep(1);
else exit(0);
I know what is zombie and orphan process but dont know how to anwser this question. Please explain me how many zombie and orphan processes can be generated by executing this code . Thanks!
There is only one fork
, so there is only 1 child. The parent exits without wait
ing for a child process. The child enter in an endless loop and shortly thereafter the parent is exists, so it becomes an orphaned process. So: 0 zombies, 1 orphaned.
However if the fork
fails, then there is no child process at all and the parent exists anyway.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.