home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sgi
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!sgigate!sgi!rhyolite!vjs
- From: vjs@rhyolite.wpd.sgi.com (Vernon Schryver)
- Subject: Re: how to dissociate from controlling terminal?
- Message-ID: <sg6ds74@rhyolite.wpd.sgi.com>
- Summary: check `man daemonize`
- Organization: Silicon Graphics, Inc. Mountain View, CA
- References: <BxvIF4.BA2@math.uwaterloo.ca>
- Date: Tue, 17 Nov 1992 22:06:47 GMT
- Lines: 35
-
- In article <BxvIF4.BA2@math.uwaterloo.ca>, gamiddle@math.uwaterloo.ca (Guy Middleton) writes:
- > How does one lose the controlling terminal on Irix? The usual BSD mechanism,
- > the TIOCNOTTY ioctl, doesn't seem to work. Is there another way?
-
- Judging from the IRIX 4.0.5 kernel source, if the process is not the
- session leader, TIOCNOTTY should work fine.
-
- Check `man daemonize` for a way to do it without pain, inspired by recent
- BSD code. Daemonize uses setsid() and closes all file descriptors, as in:
-
- if ((flags & _DF_NOFORK) == 0) {
- i = fork();
- if (i < 0)
- return -1;
- if (i != 0)
- exit(0);
- (void)setsid();
- }
-
- if ((flags & _DF_NOCHDIR) == 0)
- (void)chdir("/");
-
- if ((flags & (_DF_NOCLOSE|_DF_NOFORK)) != (_DF_NOCLOSE|_DF_NOFORK)) {
- _yp_unbind_all(); /* tell NIS its FD is dead */
- _res_close(); /* tell resolver its FD is dead */
- }
-
- if ((flags & _DF_NOCLOSE) == 0) {
- for (i = getdtablesize(); --i >= 0; ) {
- if (i != fd1 && i != fd2 && i != fd3)
- (void)close(i);
- }
-
-
- Vernon Schryver, vjs@sgi.com
-