编写系统日志消息的程序。
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
int main(void) {
openlog("slog", LOG_PID|LOG_CONS, LOG_USER);
syslog(LOG_INFO, "A different kind of Hello world ... ");
closelog();
return 0;
}
答案 0 :(得分:0)
为我工作
% cat > syslog.c
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
int main(void) {
openlog("slog", LOG_PID|LOG_CONS, LOG_USER);
syslog(LOG_INFO, "A different kind of Hello world ... ");
closelog();
return 0;
}
% cc syslog.c
% ./a.out
% tail /var/log/messages
tail: cannot open ‘/var/log/messages’ for reading: Permission denied
% su
Password:
[root@build-centos7 src]# tail /var/log/messages | grep slog
Sep 17 13:09:10 build-centos7 slog[3040]: A different kind of Hello world ...