Create process and pythoncreate process for python System Programming
I. forking process
The process generated by fork has the following features:
- Is a process clone.
- The created process exists independently of the parent process.
- The thread is copied and executed when fork () is called.
- Returns 0 in the Child thread.
- Returns the pid of the subthread in the parent thread.
- The PID of the sub-thread is different from that of the parent thread.
Ii. Sample Code
#! /Usr/bin/env pythonimport osdef child_process (): print "I am the child process and my PID is: % d" % OS. getpid () print "teh child is exiting. "def parent_process (): print" I am the parent process whit PID: % d "% OS. getpid () childId = OS. fork () if childId = 0: # child_process () else: # print "inside the parent process" print "my child's pid is: % d "% childId while True: passparent_process ()
After the sub-thread ends, the parent thread is still running and has not been released.
3. New Production threads
- OS .exe c * series Functions
- OS .exe cl
- OS .exe cle
- OS .exe cvp
- Child process overwrite parent process
It can be found that the created process overwrites the parent process. When the child process ends, the parent process also ends.