Chinaunix

标题: 进程问题,os.fork() 函数没有了吗? [打印本页]

作者: java8910    时间: 2009-11-04 10:34
标题: 进程问题,os.fork() 函数没有了吗?
我用的是 2.5.4.

代码如下:
# forks child processes until you type 'q'

import os, sys

def child( ):
    print 'Hello from child', os.getpid()
    os._exit(0)  # else goes back to parent loop

def parent( ):
    while 1:
        newpid = os.fork()
        if newpid == 0 :
            child()
        else:
            print 'Hello from parent', os.getpid(),newpid
        if raw_input() == 'q': break

parent( )



怎么报错了,


Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    help (fork)
NameError: name 'fork' is not defined


我查了一下 os 的帮助。里面没有fork() 函数了?!!!
作者: java8910    时间: 2009-11-04 10:46
书中继续写道:

Unfortunately, this won't work on Windows in standard Python today; fork is too much at odds with the Windows model, and a port of this call is still in the works (see also this chapter's sidebar about Cygwin Pythonyou can fork with Python on Windows under Cygwin, but it's not exactly the same). Because forking is ingrained in the Unix programming model, though, this script works well on Unix, Linux, and modern Macs:

原来是这样呀。。
作者: bohemia    时间: 2009-11-04 20:58
原帖由 java8910 于 2009-11-4 10:46 发表
书中继续写道:

Unfortunately, this won't work on Windows in standard Python today; fork is too much at odds with the Windows model, and a port of this call is still in the works (see also this ...


Linux下的fork




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2