一个Python脚本,想要留个接口,在进程运行过程中,修改一个使用的变量,该怎么弄呢~~~
一个笨办法:使用文件通信!!!
一个简单例子:获取某个进程的pid进行处理,指定一个pid进行处理
实现:指定的pid,通过解析文件获取,文件存在,则处理文件内容,不存在,则处理原有内容。
#!/usr/bin/env python
import os
import commands
import time
def main():
num = 0
while True:
pid = 0
if os.path.exists("pid.log"):
with open("pid.log") as fp:
pid = fp.read().strip("\r\n")
if not pid:
cmd = "ps ux | grep -v grep | grep lsd | awk {'print $2'}"
status, output = commands.getstatusoutput(cmd)
pid = output.strip()
print "pid is %s" % pid
num += 1
time.sleep(5)
if num > 100:
break
if __name__ =&#