python nohup后台运行进程
subprocess.Popen(['nohup', 'my_command'],
stdout=open('/dev/null', 'w'),
stderr=open('logfile.log', 'a'),
preexec_fn=os.setpgrp
)def preexec_function():
signal.signal(signal.SIGINT, signal.SIG_IGN)
subprocess.Popen( ... , preexec_fn=preexec_function)Popen([path] + sys.argv[1:],
stdout=DEVNULL, stderr=STDOUT, preexec_fn=ignore_sighup)nohup ... No such file or directory问题(如果使用参数,需要使用shell)
nohup ... No such file or directory问题(如果使用参数,需要使用shell) cmd = "sh myscript.sh option1"
p = subprocess.Popen(['nohup', cmd], stdout=open('/dev/null', 'w'),
stderr=open('myscript.log', 'a'),
preexec_fn=os.setpgrp )参考
Last updated