小编Nik*_*iko的帖子

等到某个过程(知道"pid")结束

我有这个:

def get_process():
    pids = []
    process = None
    for i in os.listdir('/proc'):
        if i.isdigit():
            pids.append(i)

    for pid in pids:
        proc = open(os.path.join('/proc', pid, 'cmdline'), 'r').readline()
        if proc == "Something":
            process = pid

    return process          

def is_running(pid):
    return os.path.exists("/proc/%s" % str(pid))
Run Code Online (Sandbox Code Playgroud)

然后我这样做:

process = get_process()
if process == None:
    #do something
else:
    #Wait until the process end
    while is_running(process):
        pass
Run Code Online (Sandbox Code Playgroud)

我认为这不是等待进程终止的最佳方式,必须有一些函数等待或者什么,但我找不到它.

免责声明:该流程不是子流程

python linux pid process wait

15
推荐指数
1
解决办法
1万
查看次数

标签 统计

linux ×1

pid ×1

process ×1

python ×1

wait ×1