我想运行一个Python程序来查看屏幕程序是否正在运行。如果是,那么程序不应该运行其余的代码。这是我已经和它不工作:如何判断屏幕是否在运行?
#!/usr/bin/python
import os
var1 = os.system ('screen -r > /root/screenlog/screen.log')
fd = open("/root/screenlog/screen.log")
content = fd.readline()
while content:
if content == "There is no screen to be resumed.":
os.system ('/etc/init.d/tunnel.sh')
print "The tunnel is now active."
else:
print "The tunnel is running."
fd.close()
我知道有可能在这里几件事情,并不需要而且相当多的我失踪。我将在cron中运行这个程序。
它将它写入文件。当我尝试重定向它时,它不会向该文件写入任何信息。 – spxxn 2010-04-30 16:22:51