hi,<br>       i created a daemon process   using the following code<br><br>import os<br>import sys<br># Default daemon parameters.<br># File mode creation mask of the daemon.<br>UMASK = 0<br># Default working directory for the daemon.<br>
WORKDIR = "/"<br># Default maximum for the number of available file descriptors.<br>MAXFD = 1024<br># The standard I/O file descriptors are redirected to /dev/null by default.<br>if (hasattr(os, "devnull")):<br>
   REDIRECT_TO = os.devnull<br>else:<br>   REDIRECT_TO = "/dev/null"<br>def goDaemon():<br>   try:<br>      pid = os.fork()<br>   except OSError, e:<br>      raise Exception, "%s [%d]" % (e.strerror, e.errno)<br>
   if (pid == 0):       # The first child.<br>      os.setsid()<br>      try:<br>         pid = os.fork()        # Fork a second child.<br>      except OSError, e:<br>         raise Exception, "%s [%d]" % (e.strerror, e.errno)<br>
      if (pid == 0):    # The second child.<br>         #os.chdir(WORKDIR)<br>         os.umask(UMASK)<br>      else:<br>         os._exit(0)<br>   else:<br>      os._exit(0)       # Exit parent of the first child.<br>   import resource<br>
   maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]<br>   if (maxfd == resource.RLIM_INFINITY):<br>      maxfd = MAXFD<br>   for fd in range(0, maxfd):<br>      try:<br>         os.close(fd)<br>      except OSError:   # ERROR, fd wasn't open to begin with (ignored)<br>
         pass<br>   os.open(REDIRECT_TO, os.O_RDWR)      # standard input (0)<br>   os.dup2(0, 1)                        # standard output (1)<br>   os.dup2(0, 2)                        # standard error (2)<br>   return(0)<br>
<br>it can be  seen that   the standard output and standard error are redirected to null terminal now after the  process is made daemon  i.e  after closing  all the resources and redirecting  the standard output and standard error to null terminal now  I want to print some initial msg on the console(terminal)  in which the program was started .  <br>
<b>NOTE</b>:I realize that initial msg can be printed before  closing  all the resources and redirecting  the standard output and standard error to null terminal but it necessary to print the msg   after the  process is made daemon i.e when the process actually starts  doing some processing.<br>
<br>I tried with following code:<br>fd=os.open("/dev/tty",os.O_WRONLY)<br>os.write(fd,msg)<br>os.close(fd)<br><br>but this worked fine   before  closing  all the resources and redirecting  the standard output and standard error to null terminal and after doing all these even it didn't help it didn't print any thing on the terminal <br>
<br>pls can anyone how this can be done <br><br>