Create a child process and display process id of both parent and child process.
Fork system call use for creates a new process, which is called child process, which runs concurrently with process (which process called system call fork) and this process is called parent process. After a new child process created, both processes will execute the next instruction following the fork() system call.
Library used :
os : The OS module in Python provides a way of using operating system dependent functionality. The functions that the OS module provides allows you to interface with the underlying operating system that Python is running on; be that Windows, Mac or Linux. It can be imported as –
import os
System Call Used :
Below is Python program implementing above :
# Python code to create child process import os def parent_child(): n = os.fork() # n greater than 0 means parent process if n > 0: print("Parent process and id is : ", os.getpid()) # n equals to 0 means child process else: print("Child process and id is : ", os.getpid()) # Driver code parent_child() |
Output :
Child process and id is : 32523 Parent process and id is : 32524
Note : Output can vary time to time, machine to machine or process to process.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Calculation in parent and child process using fork()
- Creating multiple process using fork()
- PyQt5 QSpinBox - Finding child using child type
- Communication between Parent and Child process using pipe in Python
- Run Python script from Node.js using child process spawn() method
- Exit status of a child process in Linux
- Creating and updating PowerPoint Presentations in Python using python - pptx
- PyQt5 QSpinBox - Finding child using ID
- PyQt5 QSpinBox - Finding children using child type
- PyQt5 QCalendarWidget - Getting child using its type
- PyQt5 QCalendarWidget - Getting child using ID
- Python | Creating tensors using different functions in Tensorflow
- Creating a Basic hardcoded ChatBot using Python-NLTK
- Creating NotePad using PyQt5 - Python
- Creating Files in HDFS using Python Snakebite
- Creating a radar sweep animation using arcade in Python
- Factorial calculation using fork() in C for Linux
- fork() and memory shared b/w processes created using it
- fork() to execute processes from bottom to up using wait()
- PyQt5 QSpinBox - Finding child through position
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

