摘要: ```cpp #include #define MAX_LEN 1024 bool debug_mode; // 使用方法同 printf void lprintf(const char *fmt, ...) { static bool print_time = true; //是否要打印时间: 当 debug_mode 为真,且上一次是换行符结尾。 char message... 阅读全文
posted @ 2018-04-15 00:31 水郁 阅读(6229) 评论(0) 推荐(0) 编辑
摘要: 通过文件独占的方式,我们打开指定的文件后,用 lockf 对文件加锁,结束程序时解锁文件。 下面代码中我们将当前程序的 PID 写入文件。 cpp int writePidFile(const char pidFile) { char str[32]; int fd = open(pidFile, 阅读全文
posted @ 2018-04-15 00:20 水郁 阅读(627) 评论(0) 推荐(0) 编辑
摘要: 守护进程的概念 守护进程(Daemon)一般是为了保护我们的程序/服务的正常运行,当程序被关闭、异常退出等时再次启动程序/恢复服务。 例如 http 服务的守护进程叫 httpd,mysql 服务的守护进程叫 mysqld。 或者有时候我们需要让我们的程序/服务能不中断地运行,在关闭终端后也能在后台 阅读全文
posted @ 2018-04-15 00:01 水郁 阅读(1583) 评论(0) 推荐(0) 编辑
……