int daemon(nochdir, noclose) int nochdir, noclose; { int fd; switch (__fork()) { case -1: return (-1); case 0: break; default: _exit(0); } if (__setsid() == -1) return (-1); if (!nochdir) (void)__chdir("/"); if (!noclose && (fd = __open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { struct stat64 st; if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) == 0 && __builtin_expect (S_ISCHR (st.st_mode), 1) != 0 #if defined DEV_NULL_MAJOR && defined DEV_NULL_MINOR && st.st_rdev == makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR) #endif ) { (void)__dup2(fd, STDIN_FILENO); (void)__dup2(fd, STDOUT_FILENO); (void)__dup2(fd, STDERR_FILENO); if (fd > 2) (void)__close (fd); } else { (void)__close (fd); return -1; } } return (0); } (c) glibc Murr ★★ (10.11.03 13:51:46 MSK) Ссылка
Обсуждалось регулярно тут, там есть нюансы, см. http://www.linux.org.ru/view-message.jsp?msgid=245840 Die-Hard ★★★★★ (10.11.03 13:55:12 MSK) Ссылка