1.fork
- 使用os模块的fork()方法可以创建一个新的进程
- 这个方法的返回值有两个,其中子进程返回0,父进程返回进程号
import os
print("start execute program ....")
# use fork create new process
ret = os.fork()
if ret ==0:
print("this is child process and pid is %s"%os.getpid())
else:
print("this is father process and pid is %s"%os.getpid())
print("%s finish"%os.getpid())
--------------------------------
/usr/bin/python3.6 /home/mark/PycharmProjects/new/process/fork_01.py
start execute program ....
this is father process and pid is 10375
10375 finish
this is child process and pid is 10376
10376 finish
Process finished with exit code 0