apue 学习记录
HuygensCheng
这个作者很懒,什么都没留下…
展开
-
apue_常用文件锁
intlock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len){ struct flock lock; lock.l_type = type; /* F_RDLCK, F_WRLCK, F_UNLCK */ lock.l_start = offset; /* byte offset, relative to l_whence */ lock.l_whence = whence; /* SEEK_SET,转载 2021-09-09 11:18:24 · 120 阅读 · 0 评论 -
apue_守护进程重读配置文件(单线程)
#include "apue.h"#include <syslog.h>#include <errno.h>extern int lockfile(int);extern int already_running(void);voidreread(void){ /* ... */}voidsigterm(int signo){ syslog(LOG_INFO, "got SIGTERM; exiting"); exit(0);}voidsigh转载 2021-09-09 11:10:26 · 115 阅读 · 0 评论 -
apue_守护进程重读配置文件的一种方法(sigwait和多线程)
#include "apue.h"#include <pthread.h>#include <syslog.h>sigset_t mask;extern int already_running(void);voidreread(void){ /* ... */}void *thr_fn(void *arg){ int err, signo; for (;;) { err = sigwait(&mask, &signo);转载 2021-09-09 11:09:09 · 98 阅读 · 0 评论 -
apue_使用文件和记录锁来保证只运行一个守护进程的一个副本
#include <unistd.h>#include <stdlib.h>#include <fcntl.h>#include <syslog.h>#include <string.h>#include <errno.h>#include <stdio.h>#include <sys/stat.h>#define LOCKFILE "/var/run/daemon.pid"#define L转载 2021-09-09 11:04:52 · 109 阅读 · 0 评论 -
apue_初始化程序调用为守护进程
#include "apue.h"#include <syslog.h>#include <fcntl.h>#include <sys/resource.h>voiddaemonize(const char *cmd){ int i, fd0, fd1, fd2; pid_t pid; struct rlimit rl; struct sigaction sa; /* * Clear file creation mask.转载 2021-09-09 11:03:02 · 80 阅读 · 0 评论 -
2021-09-08单例守护进程实现
单例守护进程实现#include <unistd.h>#include <stdlib.h>#include <fcntl.h>#include <syslog.h>#include <string.h>#include <errno.h>#include <stdio.h>#include <sys/stat.h>//#include "apue.h"//#define LOCKFILE转载 2021-09-08 20:35:30 · 119 阅读 · 0 评论