22 December 2017

Process Management in Python - os.fork()

Inspired by https://pymotw.com/3/signal/index.html, I thought of exploring os package in Python. The next few posts would be on process management and how to do it in Python. I would be showing you the code that is tiny. The goal is to provide basic code and I leave the improvision to you.

There are four important system calls - fork, exec, wait and exit that are related to process management. Interestingly Python provides equivalent APIs as a part of os package so that you can do a lot of system programming (and use it in a cool way). In this post, let us see some code that uses "os.fork" to create a new process.

os.fork() - creates a new process (often called as parent-child processes). The following code has enough comments and some explanation embedded as comments. Suggest you read the code and run it in Linux box.

Refer the Code in GIT Hub

If you want to know more about fork, refer - https://en.wikipedia.org/wiki/Fork_(system_call)

Share, comment and contribute if you like this post :-)