參考資訊:
https://github.com/pasce/daemon-skeleton-linux-c
main.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <sys/types.h> #include <sys/stat.h> #include <syslog.h> int main(int argc, char **argv) { openlog("hello", LOG_PID, LOG_DAEMON); syslog(LOG_NOTICE, "Hello, world!"); closelog(); return 0; }
執行
$ gcc main.c -o main $ ./main $ journalctl -q | grep -i hello May 18 10:24:13 debian hello[7323]: Hello, world!
P.S. Ubuntu系統下可以察看/var/log/syslog