Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 ×Ö·ûÇý¶¯2


µ¼º½£º[Ê×Ò³]>[linuxÄÚºËѧϰ±Ê¼Ç]
Ŀ¼
 [Òþ²Ø]
1 ×Ö·ûÉ豸Çý¶¯ÖªÊ¶½²½â
1.1 ÃèÊö×Ö·ûÉ豸»ù±¾½á¹¹Ìå
1.2 ×÷ÓÃ
1.3 ¸÷×Ö¶ÎÏê½â
1.4 ²Ù×÷
1.5 ÊµÀý
1.5.1 ´úÂë
1.5.2 ÔËÐÐ
[±à¼­]×Ö·ûÉ豸Çý¶¯ÖªÊ¶½²½â
×÷Õߣº[Å£ÌÎ]
[±à¼­]ÃèÊö×Ö·ûÉ豸»ù±¾½á¹¹Ìå
/linux/ ......

½èÖúsnifferÕï¶ÏLinuxÍøÂç¹ÊÕÏ


Ðá̽Æ÷(sniffer)ÔÚÍøÂ簲ȫÁìÓòÊÇÒ»°ÑË«Èн££¬Ò»·½Ãæ³£±»ºÚ¿Í×÷ΪÍøÂç¹¥»÷¹¤¾ß£¬´Ó
¶øÔì³ÉÃÜÂë±»µÁ¡¢Ãô¸ÐÊý¾Ý±»ÇԵȰ²È«Ê¼þ£»ÁíÒ»·½ÃæÓÖÔÚЭÖúÍøÂç¹ÜÀíÔ±¼à²âÍøÂç×´¿ö¡¢Õï¶ÏÍøÂç¹ÊÕÏ¡¢ÅųýÍøÂçÒþ»¼µÈ·½ÃæÓÐ×Ų»¿ÉÌæ´úµÄ×÷Óá£Ðá̽Æ÷ÊÇÆóÒµ
±Ø²»¿ÉÉÙµÄÍøÂç¹ÜÀí¹¤¾ß¡£±¾ÎÄÒÔLinuxƽ̨ÏÂÈý¸ö³£ÓõÄÍøÂçÐá̽Æ÷Tcpdump¡¢Eth ......

¹ØÓÚ s3c2416 hspi spi linux Çý¶¯


        ×î½üÔÚ×ösamsung
s3c2416
ÔÚlinuxϵÄspiÇý¶¯³ÌÐò£¬²âÊÔÁËÏÂsamsung·¢²¼µÄspiµÄÄÚºËÔ´´úÂ룬ÎÞÂÛÊDzÉÓÃdma»òÕß·Çdmaģʽ¶¼ÎÞ·¨¹¤×÷¡£ÔĶÁ¸ÃÇý¶¯´úÂ룬·¢ÏÖ
ÕâÂëÓ¦¸ÃÊÇÒ»¸öδÍê³ÉµÄ°æ±¾£¬´æÔںܶàµÄbug¡£ÓÚÊÇÔÚÕâ¸ö°æ±¾µÄ»ù´¡ÉϽøÐÐÐ޸ģ¬ÖØдһ¸ö¿ÉÓõġ¢Ö§³ÖÈ«Ë«¹¤µÄͨѶ ......

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

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

LinuxÍøÂçÇý¶¯³ÌÐò±àд£¨Ò»£©

LinuxÍøÂçÇý¶¯³ÌÐò±àд(Ò»)
¹¤×÷ÐèҪдÁËÎÒÃǹ«Ë¾Ò»¿éÍø¿¨µÄLinuxÇý¶¯³ÌÐò¡£¾­ÀúÒ»¸ö´ÓÎÞµ½ÓеĹý³Ì£¬Éî¸Ð¼¼Êõ½»Á÷µÄÖØÒª¡£Linux×÷ΪÌôս΢Èí¢¶ÏµÄÇ¿ÓÐÁ¦ÎäÆ÷£¬ÈÕÒæÊܵ½´ó¼ÒµÄϲ°®¡£ÕæÏ£ÍûËýÄÜÔÚÖйúѸËٳɳ¤¡£°Ñ³ÌÐòÎĵµÌù³öÀ´£¬Ï£ÍûºÍ´ó¼Ò̽ÌÖLinux¼¼ÊõºÍÓ¦Ó㬴ٽøLinuxÔÚÖйúµÄÆÕ¼°¡£
¡¡¡¡±¾ÎÄ¿ÉËæÒâתÔØ£¬µ«Çë²»ÒªÔ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ