Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!decwrl!wuarchive!udel!princeton!phoenix.Princeton.EDU!subbarao From: subbarao@phoenix.Princeton.EDU (Kartik Subbarao) Newsgroups: comp.unix.wizards Subject: Re: deamon 'shell' wanted Message-ID: Date: 17 May 91 21:10:59 GMT References: <417@fjcp60.GOV> Sender: news@idunno.Princeton.EDU Reply-To: subbarao@phoenix.Princeton.EDU (Kartik Subbarao) Distribution: all Organization: American Chemical Society Lines: 32 In article <417@fjcp60.GOV> brinkema@fjc.GOV (John R. Brinkema) writes: >I am writing a network daemon; it will be started up at 'rc' time. After >startup, I want it to lose all tty-group connections. I also want it to >shutdown cleanly (say when shutdown is run). > >Does anyone have an example or 'shell' for a deamon. tnx. jb. All you need to do to make sure that the daemon loses its tty associations is this: t = open("/dev/tty", O_RDONLY); ioctl(t, TIOCNOTTY, NULL); close(t); close(0); close(1); close(2); This seems to work for my daemons. As for shutting down, if process exits cleanly (i.e either voluntarily or via kill -9), then the operating system will take care of closing all fds. -Kartik -- internet% ypwhich subbarao@phoenix.Princeton.EDU -| Internet kartik@silvertone.Princeton.EDU (NeXT mail) SUBBARAO@PUCC.BITNET - Bitnet