用python编写daemon监控进程并自动恢复
下面这个程序是用于python编写daemon监控进程并自动恢复,参考http://pythonhosted.org/KiTT/_modules/kitt/daemon.html
#!/usr/bin/env python import sys, os, time, atexit from signal import SIGTERM[docs] class Daemon : """ A generic daemon class. Usage: subclass the Daemon class and override the run() method """ def __init__ ( self , pidfile , stdin = '/dev/null' , stdout = '/dev/null' , stderr = '/dev/null' , args = None ): self . stdin = stdin self . stdout = stdout self . stderr = stderr self . pidfile = pidfile self . args = args[docs] def daemonize ( self ): """ do the UNIX double-fork magic, see Stevens' "Advanced Programming in the UNIX Environment" for details (ISBN 0201563177) http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16 """ try : pid = os . fork () if pid > 0 : # exit first parent sys .</