home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / sgi / 16557 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.7 KB  |  47 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!sgigate!sgi!rhyolite!vjs
  3. From: vjs@rhyolite.wpd.sgi.com (Vernon Schryver)
  4. Subject: Re: how to dissociate from controlling terminal?
  5. Message-ID: <sg6ds74@rhyolite.wpd.sgi.com>
  6. Summary: check `man daemonize`
  7. Organization: Silicon Graphics, Inc.  Mountain View, CA
  8. References: <BxvIF4.BA2@math.uwaterloo.ca>
  9. Date: Tue, 17 Nov 1992 22:06:47 GMT
  10. Lines: 35
  11.  
  12. In article <BxvIF4.BA2@math.uwaterloo.ca>, gamiddle@math.uwaterloo.ca (Guy Middleton) writes:
  13. > How does one lose the controlling terminal on Irix?  The usual BSD mechanism,
  14. > the TIOCNOTTY ioctl, doesn't seem to work.  Is there another way?
  15.  
  16. Judging from the IRIX 4.0.5 kernel source, if the process is not the
  17. session leader, TIOCNOTTY should work fine.
  18.  
  19. Check `man daemonize` for a way to do it without pain, inspired by recent
  20. BSD code.  Daemonize uses setsid() and closes all file descriptors, as in:
  21.  
  22.         if ((flags & _DF_NOFORK) == 0) {
  23.                 i = fork();
  24.                 if (i < 0)
  25.                         return -1;
  26.                 if (i != 0)
  27.                         exit(0);
  28.                 (void)setsid();
  29.         }
  30.  
  31.         if ((flags & _DF_NOCHDIR) == 0)
  32.                 (void)chdir("/");
  33.  
  34.         if ((flags & (_DF_NOCLOSE|_DF_NOFORK)) != (_DF_NOCLOSE|_DF_NOFORK)) {
  35.                 _yp_unbind_all();       /* tell NIS its FD is dead */
  36.                 _res_close();           /* tell resolver its FD is dead */
  37.         }
  38.  
  39.         if ((flags & _DF_NOCLOSE) == 0) {
  40.                 for (i = getdtablesize(); --i >= 0; ) {
  41.                         if (i != fd1 && i != fd2 && i != fd3)
  42.                                 (void)close(i);
  43.                 }
  44.  
  45.  
  46. Vernon Schryver,  vjs@sgi.com
  47.