?????????????Daemon??????????????????????????????????????????????????????????????????Щ?????????????????????????????????Linux??????server?????????????????????Internetserverinetd??Webserverhttpd???????????????????????????????????滮????crond?????????lpd???
?????????????????????????????????????汾???Unix?????????????????????Unix?????????????????????????????????????????Щ?????????????BSD4.3???汾???System V????Linux?????????????????????Linux????????????????????????????
??????? ??????????????
??????????????????????????С??????????DOS?μ?????????TSR??????????Σ??????????????????????????????????Щ????????δ?????????д????????????????????????飬???????????????????????????Щ???????????????????????????????????shell???м?????????????????????????????????????????????Linux??????????????/etc/rc.d????????????????滮????crond????????????????????????shell????С?
???????????????Щ?????????????????????????????????????????????д????????????????????????????????????????????????????????????????????????б????????????easy?????????
???????? ?????????????
??????潲???????Unix????????????????????????????????????????????????????????????????????????????????????????????????????????????Linux?????Syetem V??SVR4?????Posix??????????????BSD4?????????????????????£?
????1. ??????С?
???????????????????Daemon????????С?????????????е???fork??????????????Daemon????????к????С?
????if(pid=fork())
????exit(0);//???????????????????????????
????2. ???????????????????????
?????б??????????Linux?е?????????????????????????????????????????????????飬????????GID????????鳤???????PID????????????????????????顣??Щ?????鹲??????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????1?????????????setsid()??????????鳤??
????setsid();
???????????????????鳤?setsid()??????????????????????????????鳤??setsid()???ó???????????μ???鳤???μ?????鳤?????????????????????????????????????????????????????????????????????
????3. ???????????δ????????
?????????????????????????鳤?????????????????????????????????????????????????鳤?????????????δ?????????
????if(pid=fork())
????exit(0);//?????????????????????????????????????????鳤??
????4. ???????????д??????
?????????????????????????????????????д?????????粻?????????????????????????????????????ж????????????????????????????·???????????
????for(i=0;i ???????????д??????close(i);>
????5. ?????????????
?????????????乤?????????????????????ж???????????????????и????????С????????????????д????????????????????и????????????/tmpchdir("/")
????6. ??????????????
???????????????????????????????????????????????????????????????????????λ????????????????????????????umask(0);
????7. ????SIGCHLD???
????????SIGCHLD??????????????????Щ??????????server????????????????????????????????????踸???????????????????????????????????zombie??????????????????踸???????????????????????????????????server???????????????Linux??????????SIGCHLD??????????SIG_IGN??
????signal(SIGCHLD??SIG_IGN);
??????????????????????????????????????????????BSD4?????BSD4?±??????????????????????????????