Conventional daemons

William J. Bogstad bogstad at hopkins-eecs-bravo.arpa
Thu Mar 27 18:05:46 AEST 1986


Keith Packard <keith%motel6.uucp at BRL.ARPA> says:
>In article <261 at bu-cs.UUCP> ccc at bu-cs.UUCP (Cameron Carson) writes:
>>	int s;
>>	for (s = 0; s < SOME_NUM; s++)
>>		(void) close(s);
>>	(void) open("/",0);
>>	(void) dup2(0,1);
>>	(void) dup2(0,2);
>>My question is: why open "/" ?  Why not open something a little
>>less vital like, say, /dev/null?
>
>Well, I suspect the answer to this lies in the dim dark past when unix
>ran on small machines.  The inode for "/" is always in memory, the
>inode for "/dev/null" is only in memory when it is referenced.
> ... Useful when your system only has 50 or so incore inodes ...

	Also, opening, "/" is not dangerous.  No one - not even root -
can write on a directory.  At least on 4.2BSD, you can't even open a
directory for writting.  So your daemon might use the directory for its
standard input but can't do any damage.

	In addition, "/" is always there.  "/dev/null" might not be
there on a slightly trashed filesystem.  If "/" is gone you can't even
boot.  A daemon you might run under those conditions is "update" the
sync() daemon.

Bill Bogstad
{umcp-cs!jhunix allegra}!hopkins!bogstad
bogstad at hopkins-eecs-bravo.arpa



More information about the Comp.unix.wizards mailing list