python實現(xiàn)的守護進程(Daemon)用法實例
更新時間:2015年06月02日 17:12:07 作者:niuniu
這篇文章主要介紹了python實現(xiàn)的守護進程(Daemon)用法,實例分析了Python進程操作的相關(guān)技巧,需要的朋友可以參考下
本文實例講述了python實現(xiàn)的守護進程(Daemon)用法。分享給大家供大家參考。具體如下:
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 demo
def 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程序設(shè)計有所幫助。
相關(guān)文章
Python OpenCV學(xué)習(xí)之圖像濾波詳解
圖像濾波的作用簡單來說就是將一副圖像通過濾波器得到另一幅圖像;明確一個概念,濾波器又被稱為卷積核,濾波的過程又被稱為卷積;實際上深度學(xué)習(xí)就是訓(xùn)練許多適應(yīng)任務(wù)的濾波器,本質(zhì)上就是得到最佳的參數(shù)。下面來跟隨小編一起深入了解一下圖像濾波吧2022-01-01
python數(shù)據(jù)分析apply(),map(),applymap()用法
這篇文章主要介紹了python數(shù)據(jù)分析apply(),map(),applymap()用法,可以方便地實現(xiàn)對批量數(shù)據(jù)的自定義操作。用法歸納如下,需要的朋友可以參考一下2022-03-03
對Python3中bytes和HexStr之間的轉(zhuǎn)換詳解
今天小編就為大家分享一篇對Python3中bytes和HexStr之間的轉(zhuǎn)換詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12
深入淺析python 協(xié)程與go協(xié)程的區(qū)別
這篇文章主要介紹了python 協(xié)程與go協(xié)程的區(qū)別 ,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-05-05

