24 December 2017

Process Management in Python - os.wait()

This is a continuation of series of posts on Process management in Python. Read this and this before continuing further. In this post, we are going to see
  1. How the parent process can get the status of its child after the child has exited using "os.wait"
  2. What happens to the child processes after they exit but the parent is still alive and did not get the status (defunct - meaning that userspace is cleared but a small about of information in kernel space is retained so as to give the information when the parent requests the status which may potentially lead to inability to create new processes)
Getting the status of the child processes is simple. Just call os.wait() to get status of any child processes or waitpid to get status of a specific process. Note, this is blocking call meaning that the parent (thread) waits here until the child is exited/terminated.

For more information on wait/waitpid, refer - https://en.wikipedia.org/wiki/Wait_(system_call)

Refer the Code in GIT Hub

Here is the code in Python (being Python, it is self-explanatory :-))


No comments: