I. Forking process
The process produced by fork has the following characteristics:
- is a clone of a process.
- The created process exists independently of the parent process.
- The thread is copied to execute at the call fork ().
- Returns 0 in the child thread.
- Returns the PID of the child thread in the parent thread
- The PID of a child thread differs from the parent thread.
Second, code example
#!/usr/bin/env pythonImportOs def child_process(): Print "I am the child process and my PID are:%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 ()ifchildID = =0:#在子进程中Child_process ()Else:#在父进程中 Print "Inside the parent process" Print "My child's PID is:%d"% childID while True:PassParent_process ()
When the child thread ends, the parent thread is still running and is not rolled out.
Third, mass production of new threads
- Os.exec* Series functions
- Os.execl
- Os.execle
- Os.execvp
- Child process Overrides parent process
You can see that a process created in this way overrides the parent process, and the parent process ends when the child process ends.
Creation process of Python system programming