首页 > 系统服务 > 详细

APUE:守护进程

时间:2017-05-27 00:29:56      阅读:425      评论:0      收藏:0      [点我收藏+]
  1. 重置文件屏蔽字 umask(0)
  2. fork(),父进程 exit(0) 以响应启动者
  3. setsid(),断开所有控制终端
  4. 修改工作目录为 /
  5. 关闭文件描述符
  6. 将 0、1、2 重定位到 /dev/null
  7. 检测是否已经存在相同的守护进程正在运行,对 /var/run/xxxd.pid 进行 lockfile()
  8. 恢复 SIGHUP 的信号处理程序为默认 SIG_DFL
  9. 主线程调用 pthread_sigmask() 屏蔽所有信号
  10. 开新线程,使用 sigwait() 等待信号,遇到 SIGHUP 重读配置文件,遇到 SIGTERM 终止
  11. 主线程完成其他工作

 

写入日志:

#define	LOG_EMERG	0	/* system is unusable */
#define	LOG_ALERT	1	/* action must be taken immediately */
#define	LOG_CRIT	2	/* critical conditions */
#define	LOG_ERR		3	/* error conditions */
#define	LOG_WARNING	4	/* warning conditions */
#define	LOG_NOTICE	5	/* normal but significant condition */
#define	LOG_INFO	6	/* informational */
#define	LOG_DEBUG	7	/* debug-level messages */

int syslog (int __pri, const char *__fmt, ...);

 

APUE:守护进程

原文:http://www.cnblogs.com/mfmans/p/6910705.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!