亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pydaemon.py

?? 藍牙通訊協議中A2DVP應用的程序
?? PY
字號:
"""Disk And Execution MONitor (Daemon)

Configurable daemon behaviors:

   1.) The current working directory set to the "/" directory.
   2.) The current file creation mode mask set to 0.
   3.) Close all open files (1024). 
   4.) Redirect standard I/O streams to "/dev/null".

A failed call to fork() now raises an exception.

References:
   1) Advanced Programming in the Unix Environment: W. Richard Stevens
   2) Unix Programming Frequently Asked Questions:
         http://www.erlenstar.demon.co.uk/unix/faq_toc.html
"""

__author__ = "Chad J. Schroeder"
__copyright__ = "Copyright (C) 2005 Chad J. Schroeder"

__revision__ = "$Id$"
__version__ = "0.2"

# Standard Python modules.
import os               # Miscellaneous OS interfaces.
import sys              # System-specific parameters and functions.

# Default daemon parameters.
# File mode creation mask of the daemon.
UMASK = 0

# Default working directory for the daemon.
WORKDIR = "/"

# Default maximum for the number of available file descriptors.
MAXFD = 1024

# The standard I/O file descriptors are redirected to /dev/null by default.
if (hasattr(os, "devnull")):
   REDIRECT_TO = os.devnull
else:
   REDIRECT_TO = "/dev/null"

def createDaemon():
   """Detach a process from the controlling terminal and run it in the
   background as a daemon.
   """

   try:
      # Fork a child process so the parent can exit.  This returns control to
      # the command-line or shell.  It also guarantees that the child will not
      # be a process group leader, since the child receives a new process ID
      # and inherits the parent's process group ID.  This step is required
      # to insure that the next call to os.setsid is successful.
      pid = os.fork()
   except OSError, e:
      raise Exception, "%s [%d]" % (e.strerror, e.errno)

   if (pid == 0):	# The first child.
      # To become the session leader of this new session and the process group
      # leader of the new process group, we call os.setsid().  The process is
      # also guaranteed not to have a controlling terminal.
      os.setsid()

      # Is ignoring SIGHUP necessary?
      #
      # It's often suggested that the SIGHUP signal should be ignored before
      # the second fork to avoid premature termination of the process.  The
      # reason is that when the first child terminates, all processes, e.g.
      # the second child, in the orphaned group will be sent a SIGHUP.
      #
      # "However, as part of the session management system, there are exactly
      # two cases where SIGHUP is sent on the death of a process:
      #
      #   1) When the process that dies is the session leader of a session that
      #      is attached to a terminal device, SIGHUP is sent to all processes
      #      in the foreground process group of that terminal device.
      #   2) When the death of a process causes a process group to become
      #      orphaned, and one or more processes in the orphaned group are
      #      stopped, then SIGHUP and SIGCONT are sent to all members of the
      #      orphaned group." [2]
      #
      # The first case can be ignored since the child is guaranteed not to have
      # a controlling terminal.  The second case isn't so easy to dismiss.
      # The process group is orphaned when the first child terminates and
      # POSIX.1 requires that every STOPPED process in an orphaned process
      # group be sent a SIGHUP signal followed by a SIGCONT signal.  Since the
      # second child is not STOPPED though, we can safely forego ignoring the
      # SIGHUP signal.  In any case, there are no ill-effects if it is ignored.
      #
      # import signal           # Set handlers for asynchronous events.
      # signal.signal(signal.SIGHUP, signal.SIG_IGN)

      try:
         # Fork a second child and exit immediately to prevent zombies.  This
         # causes the second child process to be orphaned, making the init
         # process responsible for its cleanup.  And, since the first child is
         # a session leader without a controlling terminal, it's possible for
         # it to acquire one by opening a terminal in the future (System V-
         # based systems).  This second fork guarantees that the child is no
         # longer a session leader, preventing the daemon from ever acquiring
         # a controlling terminal.
         pid = os.fork()	# Fork a second child.
      except OSError, e:
         raise Exception, "%s [%d]" % (e.strerror, e.errno)

      if (pid == 0):	# The second child.
         # Since the current working directory may be a mounted filesystem, we
         # avoid the issue of not being able to unmount the filesystem at
         # shutdown time by changing it to the root directory.
         os.chdir(WORKDIR)
         # We probably don't want the file mode creation mask inherited from
         # the parent, so we give the child complete control over permissions.
         os.umask(UMASK)
      else:
         # exit() or _exit()?  See below.
         os._exit(0)	# Exit parent (the first child) of the second child.
   else:
      # exit() or _exit()?
      # _exit is like exit(), but it doesn't call any functions registered
      # with atexit (and on_exit) or any registered signal handlers.  It also
      # closes any open file descriptors.  Using exit() may cause all stdio
      # streams to be flushed twice and any temporary files may be unexpectedly
      # removed.  It's therefore recommended that child branches of a fork()
      # and the parent branch(es) of a daemon use _exit().
      os._exit(0)	# Exit parent of the first child.

   # Close all open file descriptors.  This prevents the child from keeping
   # open any file descriptors inherited from the parent.  There is a variety
   # of methods to accomplish this task.  Three are listed below.
   #
   # Try the system configuration variable, SC_OPEN_MAX, to obtain the maximum
   # number of open file descriptors to close.  If it doesn't exists, use
   # the default value (configurable).
   #
   # try:
   #    maxfd = os.sysconf("SC_OPEN_MAX")
   # except (AttributeError, ValueError):
   #    maxfd = MAXFD
   #
   # OR
   #
   # if (os.sysconf_names.has_key("SC_OPEN_MAX")):
   #    maxfd = os.sysconf("SC_OPEN_MAX")
   # else:
   #    maxfd = MAXFD
   #
   # OR
   #
   # Use the getrlimit method to retrieve the maximum file descriptor number
   # that can be opened by this process.  If there is not limit on the
   # resource, use the default value.
   #
   import resource		# Resource usage information.
   maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
   if (maxfd == resource.RLIM_INFINITY):
      maxfd = MAXFD
  
   # Iterate through and close all file descriptors.
   for fd in range(0, maxfd):
      try:
         os.close(fd)
      except OSError:	# ERROR, fd wasn't open to begin with (ignored)
         pass

   # Redirect the standard I/O file descriptors to the specified file.  Since
   # the daemon has no controlling terminal, most daemons redirect stdin,
   # stdout, and stderr to /dev/null.  This is done to prevent side-effects
   # from reads and writes to the standard I/O file descriptors.

   # This call to open is guaranteed to return the lowest file descriptor,
   # which will be 0 (stdin), since it was closed above.
   os.open(REDIRECT_TO, os.O_RDWR)	# standard input (0)

   # Duplicate standard input to standard output and standard error.
   os.dup2(0, 1)			# standard output (1)
   os.dup2(0, 2)			# standard error (2)

   return(0)

if __name__ == "__main__":

   retCode = createDaemon()

   # The code, as is, will create a new file in the root directory, when
   # executed with superuser privileges.  The file will contain the following
   # daemon related process parameters: return code, process ID, parent
   # process group ID, session ID, user ID, effective user ID, real group ID,
   # and the effective group ID.  Notice the relationship between the daemon's 
   # process ID, process group ID, and its parent's process ID.

   procParams = """
   return code = %s
   process ID = %s
   parent process ID = %s
   process group ID = %s
   session ID = %s
   user ID = %s
   effective user ID = %s
   real group ID = %s
   effective group ID = %s
   """ % (retCode, os.getpid(), os.getppid(), os.getpgrp(), os.getsid(0),
   os.getuid(), os.geteuid(), os.getgid(), os.getegid())

   open("createDaemon.log", "w").write(procParams + "\n")

   sys.exit(retCode)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产一区二区三区| 欧美精品免费视频| 国产一区二区美女诱惑| 亚洲成人久久影院| 日韩精品一二三四| 男男视频亚洲欧美| 久久99精品久久久久| 久久精品国产一区二区三| 男女视频一区二区| 国产**成人网毛片九色| 国产91丝袜在线观看| 不卡一区二区三区四区| 一道本成人在线| 欧美日韩国产高清一区二区三区 | 中日韩免费视频中文字幕| 久久午夜免费电影| 亚洲欧美日韩成人高清在线一区| 一区二区三区欧美亚洲| 亚洲已满18点击进入久久| 日韩精品亚洲一区二区三区免费| 免费看欧美女人艹b| 国产黄人亚洲片| 在线视频综合导航| 日韩一区二区三区电影在线观看| 久久综合九色综合欧美就去吻 | 在线观看成人小视频| 欧美精品久久天天躁| 久久久久国产精品人| 亚洲免费三区一区二区| 日本不卡一二三| 高清不卡一区二区| 欧美日韩电影一区| 久久九九影视网| 亚洲一区免费观看| 国产成人午夜精品5599| 日本精品一级二级| 久久综合久久综合亚洲| 亚洲免费观看高清完整版在线观看 | 国产精品一级黄| 91蝌蚪porny| www精品美女久久久tv| 亚洲精品国产精品乱码不99| 久久av资源站| 欧美综合天天夜夜久久| 国产日韩av一区二区| 午夜亚洲福利老司机| 成人午夜av电影| 日韩精品一区二区三区四区视频 | 国产一区二区三区最好精华液| 色综合久久天天| 久久久精品人体av艺术| 丝袜美腿亚洲一区| 色综合夜色一区| 欧美国产1区2区| 蜜臀av性久久久久蜜臀aⅴ | 欧美日韩国产免费| 亚洲人精品午夜| www..com久久爱| 欧美精品一区视频| 久久丁香综合五月国产三级网站| 91在线精品秘密一区二区| 久久综合精品国产一区二区三区| 午夜精品免费在线观看| 91激情五月电影| **性色生活片久久毛片| 高清国产一区二区三区| 国产亚洲精品超碰| 韩国午夜理伦三级不卡影院| 欧美一级一区二区| 免费观看30秒视频久久| 777亚洲妇女| 日韩电影在线免费看| 欧美人狂配大交3d怪物一区| 亚洲图片欧美一区| 欧美剧在线免费观看网站| 亚洲国产精品久久艾草纯爱| 色94色欧美sute亚洲线路二 | 日韩影视精彩在线| 3d成人动漫网站| 日韩不卡一二三区| 精品久久久久久久久久久久包黑料 | 久久99日本精品| 欧美日韩美女一区二区| 日韩国产在线观看一区| 日韩欧美第一区| 激情综合一区二区三区| 久久综合色婷婷| 99久久99久久精品免费看蜜桃| 国产精品久久久久久久蜜臀| 99久久精品国产导航| 伊人开心综合网| 欧美久久一区二区| 狠狠色丁香婷婷综合| 国产精品欧美一区二区三区| va亚洲va日韩不卡在线观看| 伊人性伊人情综合网| 欧美一区二区视频免费观看| 国产一区二区三区视频在线播放| 亚洲国产精品黑人久久久| 成人亚洲一区二区一| 亚洲三级小视频| 欧美一区二区成人6969| 国产成人精品1024| 艳妇臀荡乳欲伦亚洲一区| 日韩视频永久免费| 成人毛片在线观看| 亚洲成在线观看| 国产精品嫩草99a| 欧美日韩国产综合一区二区 | 国产精品电影一区二区三区| 欧美视频你懂的| 国产精品亚洲а∨天堂免在线| 亚洲精品国产精品乱码不99| 日韩精品一区二区三区在线观看 | 国产拍欧美日韩视频二区| 99国产麻豆精品| 久久超级碰视频| 一区二区三区国产| 久久久久久久一区| 欧美日韩二区三区| av在线不卡免费看| 久久99精品网久久| 一区二区三区美女视频| 久久久三级国产网站| 欧美日本在线播放| 91丨porny丨中文| 狠狠色丁香久久婷婷综| 日精品一区二区三区| 亚洲女同女同女同女同女同69| 精品国产一区二区国模嫣然| 欧美日韩一区二区三区高清 | 视频一区二区三区中文字幕| 国产精品网站在线播放| 2023国产一二三区日本精品2022| 在线视频欧美精品| 91免费视频网| 成人精品视频一区| 国产一区二区精品在线观看| 久久精品国产一区二区三区免费看| 一区二区免费在线播放| 亚洲婷婷综合色高清在线| 国产精品毛片久久久久久| 久久综合精品国产一区二区三区| 7777精品伊人久久久大香线蕉的| 在线视频欧美精品| 在线日韩国产精品| 日本大香伊一区二区三区| heyzo一本久久综合| 国产成人免费av在线| 风间由美中文字幕在线看视频国产欧美| 精品一区二区精品| 麻豆国产欧美一区二区三区| 日本在线不卡一区| 免费看日韩a级影片| 男女男精品视频网| 国产一区二区精品在线观看| 国产精品88888| 大陆成人av片| 色94色欧美sute亚洲线路一久| 91美女片黄在线| 91麻豆视频网站| 一本色道综合亚洲| 欧美日韩情趣电影| 欧美精品国产精品| 精品国产欧美一区二区| 国产调教视频一区| 中文字幕av一区二区三区| 亚洲欧美自拍偷拍| 亚洲综合激情小说| 免费人成在线不卡| 国产成人精品免费视频网站| www.在线成人| 欧美一个色资源| 国产亚洲欧洲997久久综合| 综合欧美亚洲日本| 日韩av不卡一区二区| 91丨porny丨国产入口| 欧美日韩一区二区三区在线看| 欧美一区二区性放荡片| 日本一区二区三区四区| 亚洲日本va在线观看| 日韩精品久久久久久| 激情综合网最新| 色哟哟在线观看一区二区三区| 制服视频三区第一页精品| 精品福利视频一区二区三区| 国产精品大尺度| 老司机精品视频在线| 91老师国产黑色丝袜在线| 欧美一区二区国产| 亚洲精品欧美综合四区| 精品无人码麻豆乱码1区2区 | 国产农村妇女精品| 亚洲线精品一区二区三区| 国产综合久久久久久久久久久久 | 欧美午夜不卡在线观看免费| www亚洲一区| 日日摸夜夜添夜夜添亚洲女人| 成人av免费在线播放| 这里只有精品免费|