易截截图软件、单文件、免安装、纯绿色、仅160KB

[转] 使用Python写Linux的守护进程(daemon)

A simple unix/linux daemon in Python
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
by Sander Marechal
I've
written a simple Python class for creating daemons on unix/linux
systems. It was pieced together for various other examples, mostly
corrections to various Python Cookbook
articles and a couple of examples posted to the Python mailing lists.
It has support for a pidfile to keep track of the process. I hope it's
useful to someone.
Below is the Daemon class. To use it, simply subclass it and implement the run() method.
import sys, os, time, atexit
from signal import SIGTERM
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'):
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
self.pidfile = pidfile

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.exit(0)
except OSError, e:
sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
sys.exit(1)

# decouple from parent environment
os.chdir("/")
os.setsid()
os.umask(0)

# do second fork
try:
pid = os.fork()
if pid > 0:
# exit from second parent
sys.exit(0)
except OSError, e:
sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
sys.exit(1)

# redirect standard file descriptors
sys.stdout.flush()
sys.stderr.flush()
si = file(self.stdin, 'r')
so = file(self.stdout, 'a+')
se = file(self.stderr, 'a+', 0)
os.dup2(si.fileno(), sy


相关文档:

在linux下安装遇到的环境变量问题

 今天在安装oracle过程中,参照网上下载的资料在RHEL5上安装oracle,整个过程比较顺利,但是却遇到了一点问题,虽然不是很严重,但是毕竟是个问题心里还是不很舒服,在此请路过的解决。
      主要问题是oracle用户的环境变量,在安装oracle过程中,有一步是需要以oracle用户登录,然后编辑 ......

Linux 下常用软件的安装命令(转载)

 sudo apt-get install virtualbox
sudo apt-get install ntfs-3g ntfs-config #ntfs写入支持,装完后运行ntfs-config,把两个钩打上即可。楼下方法作废
sudo apt-get install googleearth googlizer gtalk#google相关,skyx友情提示:不推荐马甲 gtalk
sudo apt-get install ghex #GNOME 上的十六进制文件编辑器
su ......

linux下tomcat自启动

-----------------------------------------------------------
#!/bin/bash
#
# Startup script for the tomcat
#
# chkconfig: 345 95 15
# description: tomcat service script
#
# Source function library.
. /etc/rc.d/init.d/functions
TOMCAT_HOME=/home/tomcat
RETVAL=0
checkjava(){
if [ -z "$JAVA ......

linux top命令详解

top命令和ps命令的基本作用是相同的,显示系统当前的进程和其它状况;但是top是一个动态显示过程,即可以通过用户按键来不断刷新当前状态。如果在前台执行该命令,它将独占前台,直到用户终止该程序为止。比较准确的说,top命令提供了实时的对系统处理器的状态监视。它将显示系统中CPU最“敏感”的任务列表。该命 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号