First we know that the most obvious difference between a process and a thread is:
In a multi-process environment, each process has its own process data, and the process data is independent of each other. A process can have multiple threads, and multiple threads share the process's data.
#-*-Coding:utf-8-*-
Import OS
From NT Import getpid
Print ("Current ID:%d" %getpid ())
Output
Current id:17452
To create a process:
The creation process, the Linux fork, and the Linux environment under the C Programming fork function, for the parent process, the return is the child process PID, for the child process, the return is 0
From os import *
Print ("Current ID:%d" %getpid ())
PID = Fork()
If PID = = 0:
Print ("I am the child process:%d" %getpid ())
Else
Print ("I am parent process, my pid is%d, child process%d" %getpid (), PID)
Python is a platform-based language, so under Windows, Python's multiprocessing module enables multi-process programming.
Here's a simple example.
From multiprocessing import Process
From NT Import getpid
def my_proc():
Print (' I am the proc, pid(%d) ' %getpid ())
If __name__==' __main__ ':
Print (' Parent process%s. ' %getpid ())
p = Process (Target=my_proc)
Print (' Process would start. ')
P.start ()
P.join ()
Print (' Process end. ')
Python multi-process and multi-threaded---(self-learning, persistent update)