python实现的守护进程(Daemon),pythondaemon,def createDa
文章由Byrx.net分享于2019-03-23 11:03:04
python实现的守护进程(Daemon),pythondaemon,def createDa
def createDaemon(): ”’Funzione che crea un demone per eseguire un determinato programma…”’ import os # create - fork 1 try: if os.fork() > 0: os._exit(0) # exit father… except OSError, error: print ‘fork #1 failed: %d (%s)’ % (error.errno, error.strerror) os._exit(1) # it separates the son from the father os.chdir(’/') os.setsid() os.umask(0) # create - fork 2 try: pid = os.fork() if pid > 0: print ‘Daemon PID %d’ % pid os._exit(0) except OSError, error: print ‘fork #2 failed: %d (%s)’ % (error.errno, error.strerror) os._exit(1) funzioneDemo() # function demodef funzioneDemo(): import time fd = open('/tmp/demone.log', 'w') while True: fd.write(time.ctime()+'\n') fd.flush() time.sleep(2) fd.close()if __name__ == '__main__': createDaemon()
相关内容
- python多线程Ping网段,python多线程ping,import sysim
- python一行代码打印九九乘法表,python一行乘法,python一行
- webpy获得checkbox数组的值,webpycheckbox数组,webpy中获得选
- 使用python查询google pr值代码,pythonpr,如下代码查询网站
- python创建临时文件夹,python创建文件夹,import tempf
- python获得文件扩展名,python文件扩展名,import os.pa
- python实现希尔排序算法,python希尔算法,希尔排序(Shel
- python 读取系统环境变量,python环境变量,#!/usr/bin/e
- python property使用示例,pythonproperty,假设类的某属性,你
- python使用smtplib发邮件(带附件)代码,pythonsmtplib,简单
评论关闭