test.py

import os
import string

def run(program, *args):
    file = program
    result = os.spawnv(os.P_WAIT, file, (file,) + args)
    print result

run("/usr/bin/python", "/scripts/hello.py")

while True:
    time.sleep(10)

注:
1、os.P_WAIT  父进程挂起直到子进程执行完毕,返回进程退出时的状态码。
os.P_NOWAIT  父进程和子进程同时运行,返回新进程的id

2、os.spawnv的参数形式需要严格按上图所示,file是环境变量的绝对路径,
只记录python会出错,os.P_NOWAIT模式对应的子进程是一个僵尸进程

os.P_WAIT模式返回127,实际的程序没有执行。

 

hello.py

import os
import sys
import time

while True:
    print "hello"
    time.sleep(10)

 

posted on 2018-02-11 15:04  妞溜溜  阅读(979)  评论(0编辑  收藏  举报