5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Copyright (C) 2006 The Trustees of Princeton University
8 # $Id: pl_mom.py,v 1.4 2006/06/02 04:00:00 mlhuang Exp $
16 Check PID file. Exit if already running. Update PID file.
20 pidfile = file("/var/run/%s.pid" % prog, "r")
21 pid = pidfile.readline().strip()
23 if os.path.isdir("/proc/" + pid):
24 print "Error: Another copy of %s is still running (%s)" % (prog, pid)
29 pidfile = file("/var/run/%s.pid" % prog, "w")
30 pidfile.write(str(os.getpid()))
35 os.unlink("/var/run/%s.pid" % prog)
40 Daemonize self. Detach from terminal, close all open files, and fork twice.
45 # Detach from terminal
56 # Close all open file descriptors
58 maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
59 if (maxfd == resource.RLIM_INFINITY):
61 for fd in range(0, maxfd):
67 # Redirect stdin to /dev/null
68 os.open("/dev/null", os.O_RDWR)