码迷,mamicode.com
首页 > 编程语言 > 详细

python多进程之fork

时间:2017-12-16 20:31:59      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:process   python3.6   for   markdown   blog   use   tar   class   this   

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

python多进程之fork

标签:process   python3.6   for   markdown   blog   use   tar   class   this   

原文地址:http://www.cnblogs.com/endurance9/p/8047431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!