Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

fork function in python

# 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()
Comment

Python os.fork() function

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import time

for i in range(2):
    print '**********%d***********' % i
    pid = os.fork()
    if pid == 0:
        # We are in the child process.
        print "%d (child) just was created by %d." % (os.getpid(), os.getppid())
    else:
        # We are in the parent process.
        print "%d (parent) just created %d." % (os.getpid(), pid)
Comment

PREVIOUS NEXT
Code Example
Python :: python how to get the last element in a list 
Python :: python argparse file argument 
Python :: how to import numpy in python 
Python :: how to run pyttsx3 in a loop 
Python :: Calculate Euclidean Distance in Python using distance.euclidean() 
Python :: how to create dictionary between two columns in python 
Python :: clean column names pandas 
Python :: can list comprehenios contain else 
Python :: find percentage of missing values in a column in python 
Python :: python get function name 
Python :: read file contents python 
Python :: pandas earliest date in column 
Python :: python get all combinations of list 
Python :: pygame.draw.rect() 
Python :: import antigravity in python 
Python :: django collectstatic 
Python :: most frequent word in an array of strings python 
Python :: python character list to string 
Python :: pass keyword python 
Python :: django now template tag 
Python :: how to run terminal commands in python 
Python :: python dictionary sort 
Python :: how to use function in python 
Python :: get multiple inputs in python 
Python :: embed image in html from python 
Python :: python dictionary default 
Python :: charts in python 
Python :: how to create a variable in python 
Python :: import python script from another directory 
Python :: django active link 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =