Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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Óëuclinux ÄÚ´æ¹ÜÀí£¨1£©

Ó¦¸Ã˵uClinuxͬ±ê×¼LinuxµÄ×î´óÇø±ð¾ÍÔÚÓÚÄÚ´æ¹ÜÀí£¬Í¬Ê±Ò²ÓÉÓÚuClinuxµÄÄÚ´æ¹ÜÀíÒý·¢ÁËһЩ±ê×¼LinuxËù²»»á³öÏÖµÄÎÊÌâ¡£±¾ÎĽ«°ÑuClinuxÄÚ´æ¹ÜÀíͬ±ê×¼LinuxµÄÄÇÄÚ´æ¹ÜÀí²¿·Ö½øÐбȽϷÖÎö¡£
±ê×¼LinuxʹÓõÄÐéÄâ´æ´¢Æ÷¼¼Êõ
±ê×¼LinuxʹÓÃÐéÄâ´æ´¢Æ÷¼¼Êõ£¬ÕâÖÖ¼¼ÊõÓÃÓÚÌṩ±È¼ÆËã»úϵͳÖÐʵ¼ÊʹÓõÄÎïÀíÄÚ´æ´óµÃ¶àµÄÄÚ´æ ......

ÔÚlinuxÏ°²×°Óöµ½µÄ»·¾³±äÁ¿ÎÊÌâ

 ½ñÌìÔÚ°²×°oracle¹ý³ÌÖУ¬²ÎÕÕÍøÉÏÏÂÔصÄ×ÊÁÏÔÚRHEL5ÉÏ°²×°oracle£¬Õû¸ö¹ý³Ì±È½Ï˳Àû£¬µ«ÊÇÈ´Óöµ½ÁËÒ»µãÎÊÌ⣬ËäÈ»²»ÊǺÜÑÏÖØ£¬µ«ÊDZϾ¹ÊǸöÎÊÌâÐÄÀﻹÊDz»ºÜÊæ·þ£¬ÔÚ´ËÇë·¹ýµÄ½â¾ö¡£
      Ö÷ÒªÎÊÌâÊÇoracleÓû§µÄ»·¾³±äÁ¿£¬ÔÚ°²×°oracle¹ý³ÌÖУ¬ÓÐÒ»²½ÊÇÐèÒªÒÔoracleÓû§µÇ¼£¬È»ºó±à¼­ ......

linuxÈíÖжϻúÖÆ


 
 
linuxÈíÖжϻúÖÆ
 
 
ÖжϷþÎñ³ÌÐòÍùÍù¶¼ÊÇÔÚCPU¹ØÖжϵÄÌõ¼þÏÂÖ´Ðеģ¬ÒÔ±ÜÃâÖжÏǶÌ׶øʹ¿ØÖƸ´ÔÓ»¯¡£µ«ÊÇCPU¹ØÖжϵÄʱ¼ä²»ÄÜÌ«³¤£¬·ñÔòÈÝÒ׶ªÊ§ÖжÏÐźš£Îª´Ë£¬ Linux½«ÖжϷþÎñ³ÌÐòÒ»·ÖΪ¶þ£¬¸÷³Æ×÷“Top Half”ºÍ“Bottom Half”¡£Ç°Õßͨ³£¶Ôʱ¼äÒªÇó½ÏΪÑϸñ£¬ ......

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

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

linux½ø³Ìµ÷¶ÈÕþ²ß


½ø³Ìµ÷¶ÈÕþ²ß¾ÍÊǵ÷¶ÈϵͳÖÖÄÄÒ»¸ö½ø³ÌÀ´CPUÔËÐС£ÕâÖÖµ÷¶È·Ö2²ã¿¼ÂÇ¡£
µÚÒ»²ã£¬½ø³Ì״̬Õâ¸öÊÇ×îÓÅÏÈ¿¼Âǵģ¬Ò²¾ÍÊÇ˵ÓÅÏȼ¶×î¸ßµÄ¡£ÔÚlinuxÖÐÖ»ÓоÍÐ÷̬µÄ½ø³Ì²ÅÓпÉÄܻᱻµ÷¶ÈÑ¡ÖÐÈ»ºóÕ¼ÓÐCPU£¬ÆäËü״̬µÄ½ø³Ì²»¿ÉÄÜÕ¼Óеĵ½CPU¡£ÏÂÃæÊÇlinuxÖнø³ÌµÄ״̬
TASK_RUNNING:¾ÍÐ÷״̬£¬µÃµ½CPU¾Í¿ÉÒÔÔËÐС£
TASK_INTERRU ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ