1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)daemon.c 5.1 (Berkeley) 06/15/90"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/file.h> 13 14 daemon() 15 { 16 int cpid; 17 18 if ((cpid = fork()) == -1) 19 return (-1); 20 if (cpid) 21 exit(0); 22 23 (void) setsid(); 24 (void) chdir("/"); 25 (void) close(0); 26 (void) close(1); 27 (void) close(2); 28 (void) open("/", O_RDONLY, 0); 29 (void) dup2(0, 1); 30 (void) dup2(0, 2); 31 } 32