Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ÈçºÎ×ß³ö×ÀÃæÀ§¾³£¿

       ½üÈÕ£¬ÔÚLinuxCON 2009´ó»áÉÏ£¬×ÀÃæ Linux ÓÖ³ÉΪҵ½ç¹Ø×¢µÄ½¹µãÖ®Ò»¡£¸÷ÖÖ²»Í¬µÄÉùÒô£¬É¤ÃŶ¼ºÜ´ó¡£ÔÚÕâ·×·×ÈÂȵķÕΧÖУ¬ Linux ÈçºÎ×ß³ö×ÀÃæÀ§¾³£¿
       ×ݹÛÈ«¾Ö£¬ÆÕ¼°×ÀÃæ Linux µÄ×î´óÕÏ°­Ö®Ò»ÊÇϵͳ°²×°µÄ²Ù×÷À§ÄÑÐÔ¡£Ô¤×° Windows Òѳɴó ......

linux shellºÍÅäÖÃÎļþµÄÖ´ÐÐ˳Ðò

Ò»¡¢bash shellµÄ·ÖÀࣺ
     µÇ¼shell:Óû§µÇ¼linuxÖ÷»úʱȡµÃµÄshell.
     ·ÇµÇ¼shell£ºÓû§µÇ¼linuxÖ÷»úºó£¨È¡µÃÁ˵Ǽshell£©ÓÉÓÚÐèÒªÆô¶¯Ö´ÐеÄshell,È磺ÓÃsuÇл»Óû§ºóÈ¡µÃµÄshell;ÔڵǼshellÖÐ
          &nb ......

Linux Îļþϵͳ¸ÅÊö£¨Linux Sir£©

Linux Îļþϵͳ¸ÅÊö

×÷Õߣº±±ÄÏÄϱ±
À´×Ô£ºLinuxSir.Org
ÕªÒª£º ±¾ÎÄͨ¹ýÎļþϵͳµÄ¶¨Òå˵Æð£¬È»ºóͨ¹ýÒýÎļòµ¥µÄ½éÉÜÁËÒ»ÏÂÎļþϵͳÀàÐÍ£»¶ÔLinux³£ÓõÄext2¡¢ext3¼°reiserfs ¸ù¾Ý±¾ÈËʹÓþ­ÑéÒ²·º·ºµÄ̸ÁË̸£¬µ«²¢²»ÊÇרҵµÄ¡£ÈçºÎÔĶÁ±¾ÎÄ£¬»¹ÊÇÓÃÂí¿Ë˼ÀíÂÛ¸æËßÎÒÃǵķ½·¨£ºÒ»·ÖΪ¶þ£¬±ß¿´±ßÅú°É£»
Ŀ¼Ë÷Òý
Ò» ......

Linux ´´½¨Îļþϵͳ¼°¹ÒÔØÎļþϵͳÁ÷³ÌÏê½â

Linux ´´½¨Îļþϵͳ¼°¹ÒÔØÎļþϵͳÁ÷³ÌÏê½â
×÷Õߣº±±ÄÏÄϱ±
À´×Ô£º LinuxSir.Org
ÕªÒª£º±¾ÎĶÔÐÂÔöÓ²ÅÌ£¬ÇиîÓ²ÅÌ£¬´´½¨Ó²ÅÌ·ÖÇø£¬ÎªÓ²ÅÌ·ÖÇø´´½¨Îļþϵͳ£¬ÒÔ¼°¼ÓÔØÎļþϵͳµÄÁ÷³Ì×ö×ܽáÐÔÂÛÊö£»Ö÷ÒªÊÇΪ³õѧÕßŪÇå³þÕâÒ»²Ù×÷¹ý³Ì£»±¾ÎÄ
Éæ¼°fdisk¡¢mkfs¡¢mount ... ... µÈ¹¤¾ß£»¶Ô/etc/fstab ½øÐÐÁ˽â˵£»»¹ÓдÅÅÌɨà ......

LinuxÍøÂçÇý¶¯³ÌÐò±àд(ËÄ)

¡¡Èý.±àдLinuxÍøÂçÇý¶¯³ÌÐòÖÐÐèҪעÒâµÄÎÊÌâ
¡¡¡¡3.1 ÖжϹ²Ïí
¡¡¡¡LinuxϵͳÔËÐм¸¸öÉ豸¹²Ïíͬһ¸öÖжϡ£ÐèÒª¹²ÏíµÄ»°£¬ÔÚÉêÇëµÄʱºòÖ¸Ã÷¹²Ïí·½Ê½¡£ÏµÍ³ÌṩµÄrequest_irq()µ÷ÓõĶ¨Ò壺
¡¡¡¡¡¡¡¡int request_irq(unsigned int irq,
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡void (*handler)(int irq, void *dev_id, struct pt_regs *re ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ