0

To explain, I am not asking how to reap a process.

In C, the parent process must explicitly reap a created child, even if the child exited by performing an exit() function call.

I understand that while reaping the child, it may be necessary to obtain the exit status of the child. In fact, that is the only information that may be obtained from the child process. So, why does the OS not just store the exit status(an integer), but rather, still store all the memory associated with the child until reaped?

1 Answer 1

4

The premise of your question is wrong. The OS does store just the exit status (and resource-usage-report), but most importantly of all, it also reserves the pid until you wait on it. This last part is important because, if the pid were reassigned to a new process before you waited on the original one, it would be impossible to use it as an identifier to request the exit status.

3
  • Thanks for your answer, so it is not such a big deal: not to reap a child process? As only a small amount of memory that is wasted right?
    – Sush
    Mar 27, 2015 at 22:20
  • 1
    No. There are only finitely many pids available: at most, 2^(8*sizeof(pid_t)), and in practice often as few as 32768. Individual users may even be subject to much lower limits. If you do not wait on them, they'll eventually be exhausted and you cannot make more processes. Mar 27, 2015 at 22:21
  • In case it wasn't clear: the OS is not unnecessarily wasting resources that could be freed during the interval between process exit and waiting on the pid, but it does necessarily prevent reuse of an important resource -- the space of process identifiers -- until you wait. Mar 27, 2015 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.