python:如何在Linux中编写守护进程
I have a .py file that is ran by:
我有一个。py文件:
python a.py &
python。py &
I am using a ssh to run the command, after it I have to log off. I find after some time the process is exited. I suspect it's Linux send some signal to it? I think if I can make the daemon then I can avoid this?
我正在使用ssh运行这个命令,在它之后我必须注销。我怀疑是Linux给它发送信号?我想如果我能做这个守护进程我就能避免这个?
5 个解决方案
#1
7
Although nohup will work, it's a quick and dirty solution. To make a proper daemon process you need to use SysV init or (If you are running Ubuntu 6.10+ or Fedora 9+) upstart.
尽管nohup是有效的,但它是一个快速而肮脏的解决方案。要做一个适当的守护进程,您需要使用SysV init或(如果运行Ubuntu 6.10+或Fedora 9+) upstart。
Here's a simple script that starts a.py and restarts it whenever it gets killed (up to 5 times inside a 5 minute span):
下面是一个启动a的简单脚本。当它被杀死时(在5分钟内最多5次),就重新启动:
respawn
respawn limit 5 300
exec python /path/to/a.py
Then just put that script in /etc/init/
.
然后把这个脚本放到/etc/init/中。
Upstart has a lot more options too. Checkout the Quick Start tutorial.
Upstart也有更多的选项。签出快速入门教程。
更多相关文章
- python解压zip脚本
- 使用python脚本配置zabbix发送报警邮件
- 见证历史!Python或将取代VBA,成为Excel官方脚本语言!
- Python标准库06 子进程 (subprocess包)
- 解决Linux下运行Python脚本显示“: 没有那个文件或目录”的问题
- 通过Excel / VBA运行Python脚本
- Python3 串口两进程同时读写
- 利用Dnspod api批量更新添加DNS解析【python脚本】
- 是否可以在没有安装铁python的PC上运行编译的铁python脚本?