Creating child process using fork() in Python Last Updated : 12 Dec, 2017 Comments Improve Suggest changes Like Article Like Report 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 : fork() : fork() is an operation whereby a process creates a copy of itself. It is usually a system call, implemented in the kernel. getpid() : getpid() returns the process ID (PID) of the calling process. Below is Python program implementing above : Python3 # 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. Comment More infoAdvertise with us Next Article Creating child process using fork() in Python S Sharad_Bhardwaj Follow Improve Article Tags : Misc Python Python-Library system-programming Practice Tags : Miscpython Similar Reads Creating multiple process using fork() Prerequisite - Introduction of fork, getpid() and getppid() Problem statement - Write a program to create one parent with three child using fork() function where each process find its Id. For example : Output :parent 28808 28809 my id is 28807 First child 0 28810 my id is 28808 Second child 28808 0 3 min read Kill a Process by name using Python A process is identified on the system by what is referred to as a process ID and no other process can use that number as its process ID while that first process is still running. Imagine you are a system administrator of a company and you start an application from your menu and you start using that 2 min read Understanding âforkâ and âspawnâ in Python Multiprocessing Pythonâs multiprocessing library provides a powerful way to leverage multiple processor cores for concurrent execution, enhancing the performance of computationally intensive tasks. One of the intriguing aspects of multiprocessing is the ability to initiate new processes using various start methods. 6 min read Calculation in parent and child process using fork() Write a program to find sum of even numbers in parent process and sum of odd numbers in child process. Examples: Input : 1, 2, 3, 4, 5 Output : Parent process Sum of even no. is 6 Child process Sum of odd no. is 9 Explanation: Here, we had used fork() function to create two processes one child and o 2 min read Run Python script from Node.js using child process spawn() method Node.js is one of the most adopted web development technologies but it lacks support for machine learning, deep learning and artificial intelligence libraries. Luckily, Python supports all these and many more other features. Django Framework for Python can utilize this functionality of Python and ca 3 min read Like