Python检查fork()进程是否完成 [英] Python checking if a fork() process is finished

查看:64
本文介绍了Python检查fork()进程是否完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否有人可以帮助我.我遇到的问题是,我os.fork()获取了几条信息并将它们发送到文件中,但是要检查fork过程是否无法正常工作.

Just wondering if some one could help me out. The problem I'm having is that I os.fork() to get several bits of information and send them to a file, but checking to see if the fork process is not working.

import sys
import time
import os
import re


ADDRESS  = argv[1]
sendBytes = argv[2]


proID2 = os.fork()
if proID2 == 0:
    os.system('ping -c 20 ' + ADDRESS + ' > testStuff2.txt')
    os._exit(0)

print proID2

finn = True
while finn == True:
time.sleep(1)
finn = os.path.exists("/proc/" + str(proID2))
print os.path.exists("/proc/" + str(proID2))
print 'eeup out of it ' + str(proID2)

我认为os.path.exists()可能不是正确的选择.

I think that the os.path.exists() is maybe not the right thing to use.

谢谢.

推荐答案

要等待子进程终止,请使用os.waitXXX()函数之一,例如

To wait for the child process to terminate, use one of the os.waitXXX() functions, such as os.waitpid(). This method is reliable; as a bonus, it will give you the status information.

这篇关于Python检查fork()进程是否完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆