Reaping zombie process - child

后端 未结 1 1332
悲哀的现实
悲哀的现实 2020-12-21 13:48

I am taking command line arguments to main from parent to child and counting them and printing. My question is that i am not sure that i am reaping the child? dont i just ne

相关标签:
1条回答
  • 2020-12-21 13:54

    No, you are not reaping the child correctly. In your case, if the child process finishes before the parent process exits, the child will become a zombie. Then, when the parent process finishes, the child will be reparented to init (whether it has finished and is a zombie, or is still running). init is then reaping the child for you.

    To reap the child, add a call to wait() before exit.

    By the way, you have another bug - you are creating the pipe after the fork, so the parent and child each create a (different) pipe - they're not connected. Move the if (pipe(... up before the fork().

    0 讨论(0)
提交回复
热议问题