如何写一个deamon程序?
发信站: BBS 水木清华站 (Fri Nov 27 01:22:52 1998)
【 在 gjx (小侃帝) 的大作中提到: 】
: as titile who can tell me !
: thansks
1> ignore the signals, SIGINT, SIGQUIT, SIGTRAP, SIGIOT, SIGTERM, etc
signal(xxx,SIGIGN);
2> close all the file descriptors
for (i=32,i>=3,i--)
close(i);
3> fork (maybe twice)
4> chdir("/")
5> umask(0)
6> call setpgrp() to become the head of the new process group
Some steps can be omitted.
You can make it. Good luck!
--
注:另外在《Linux从入门到精通》书中也有讲解。
本文转自中文Linux论坛