我需要在Ubuntu服务器(Amazon EC2)上运行一些无限循环的python脚本。 我真的很喜欢使用nohup,因为它很简单,我可以有output.out日志文件。 我开始像脚本一样
nohup script.py > output.out &
该过程开始。 我用工作检查 – 一切都很好。 然后我closuresterminal并用作业login检查进程-l,我再也看不到了。 你能告诉我我做错了什么吗?
如果你改变会话(注销并回来),你不可能看到你的脚本作为工作。
试试ps 。
ps -u myuser
用实际loginreplacemyuser
如果您在使用jobs -l时可以看到您的作业,则您可以将其从会话中删除
保持脚本运行的另一种方法是使用screen工具。
尝试redirect所有的I / Ostream
nohup script.py < /dev/null > output.out 2> error.out &
长的解释 :
后台运行进程(作业)始终绑定到特定的terminal:
[11] user @ lab7-11:〜> nohup ./test.sh> out& [1] 39978 [11] user @ lab7-11:〜> ps aux | grep 39978 用户39978 0.0 0.0 106096 1156 pts / 11 S 06:15 0:00 bash ./test.sh
当它被绑定到terminal时,您可以在jobs输出中看到它:
[11]user@lab7-11:~> jobs -l [1]+ 39978 Running nohup ./test.sh > out &
closures那个terminal之后,你的工作就变成了守护神 ,并没有更多的terminal
[7] user @ lab7-11:〜> ps aux | grep 39978 用户39978 0.0 0.0 106096 1156 ? S 06:15 0:00 bash ./test.sh
所以,在这个阶段,你可以按照@Archemar的build议通过ps检查你的进程的状态,但是不能通过job
简短的解释:你的脚本没有被杀死 – 它变成了守护进程。