博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Programming Python - 2. System Tools -2.5 Parallel System Tools
阅读量:4659 次
发布时间:2019-06-09

本文共 1121 字,大约阅读时间需要 3 分钟。

Forking is based on the notion of copying programs: when a program calls the fork routine, the

operating system makes a new copy of that program and its process in memory and
starts running that copy in parallel with the original. Some systems don’t really copy
the original program (it’s an expensive operation), but the new copy works as if it were
a literal copy.

 

all forked processes run independently and in parallel under the operating system’s control, and

children may continue to run after their parent exits.

 

os.fork built-in function. Because this function

generates a copy of the calling program, it returns a different value in each copy: zero
in the child process and the process ID of the new child in the parent

import osdef child():    print("hello from child", os.getpid())    os.exit(0)def parent():    while True:        newpid=os.fork()        if newpid==0:            child()        else:            print("hello from parent",os.getpid(), newid)        if input()=='q': breakparent()

 

*fork cannot work well in typical win; but can work under cygwin

转载于:https://www.cnblogs.com/jsquare/p/3619930.html

你可能感兴趣的文章
HDU 3374 String Problem
查看>>
数据集
查看>>
[Leetcode] unique paths ii 独特路径
查看>>
HDU 1217 Arbitrage (Floyd + SPFA判环)
查看>>
IntelliJ idea学习资源
查看>>
Django Rest Framework -解析器
查看>>
ExtJs 分组表格控件----监听
查看>>
Hibernate二级缓存配置
查看>>
LoadRunner常用术语
查看>>
关于jedis2.4以上版本的连接池配置,及工具类
查看>>
记忆讲师石伟华微信公众号2017所有文章汇总(待更新)
查看>>
FactoryBean
查看>>
Coolite动态加载CheckboxGroup,无法在后台中获取
查看>>
C3P0连接池工具类使用
查看>>
SVN常用命令备注
查看>>
孩子教育
查看>>
解决Cacti监控图像断断续续问题
查看>>
结构体的传参理解成员的存储方式
查看>>
python 进程与线程(理论部分)
查看>>
什么是API
查看>>