当前位置:网站首页>系统 日志
系统 日志
2022-06-12 19:35:00 【Lee Neo】
/var/log
syslogd服务

系统日志实例:
tail -f /tmp/out //查看输出;
ps -axj //查看运行
tail -f /var/log/syslog //查看日志
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include <syslog.h>
#include<errno.h>
#define FNAME "/tmp/out"
static int daemonize(void)
{
int fd;
pid_t pid;
pid = fork();
if(pid <0)
{
exit(1);
}
if(pid >0)
exit(0);
fd = open("/dev/null", O_RDWR);
if(fd < 0)
{
return -1;
}
// 标准流重定向到“黑洞”,即在终端不显示
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
if(fd > 2)
close(fd);
setsid();
chdir("/");
// umask(0);
return 0;
}
int main()
{
FILE *fp;
openlog("mydaemon", LOG_PID, LOG_DAEMON);
if(daemonize())
{
syslog(LOG_ERR, "daemonize() failed!");
}
else
{
syslog(LOG_INFO, "daemonize() successded!");
}
fp = fopen(FNAME, "w");
if(fp == NULL)
{
syslog(LOG_ERR, "fopen():%s", strerror(errno));
exit(1);
}
syslog(LOG_INFO, "%s was opened.", FNAME);
for(int i = 0; ; i++ )
{
fprintf(fp, "%d\n", i);
fflush(fp);
syslog(LOG_DEBUG, "%d is printed.", i);
sleep(1);
}
fclose(fp);
closelog();
exit(0);
}边栏推荐
- Research Report on global and Chinese cosmetics industry market sales scale forecast and investment opportunities 2022-2028
- [blockbuster release] ant dynamic card, enabling the app home page to realize agile update
- 王学岗room+paging3
- Market development planning and investment prospect analysis report of Chinese government investment and financing platform 2022-2027
- YOLOX网络结构详解
- 94. 解析网页中的内容
- 设备管理-借还模块界面代码
- Market scale forecast and future competitive trend outlook report of China's plastic and cosmetic industry 2022-2028
- Leetcodesql: count the number of students in each major
- Implementation of VGA protocol based on FPGA
猜你喜欢

Promise to solve hell function calls can be used infinitely

基于微信电子书阅读小程序毕业设计毕设作品(2)小程序功能

【5GC】三种SSC(Session and Service Continuity)模式介绍

Pyinstaller packaging tutorial packaging resource files
![[generation confrontation network learning III] reading notes of Bigan paper and its principle understanding](/img/6b/0f0815e20cdf6da28793562bcaede1.png)
[generation confrontation network learning III] reading notes of Bigan paper and its principle understanding

Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice

Storage system overview

Shell programming regular expressions and metacharacters

基于微信电子书阅读小程序毕业设计毕设作品(5)任务书

Attack and defense world (WEB) -- supersqli
随机推荐
基於分布式數據庫本身的定時備份方法
Shell 数组和函数
Software usage of Tencent cloud TDP virt viewer win client
RT-Thread 模拟器 simulator 搭建 LVGL 的开发调试环境
Global and Chinese smart government industry market research and investment risk outlook report 2022-2028
Equipment management - borrowing / returning module interface code
今晚7:00 | PhD Debate 自监督学习在推荐系统中的应用
"As a service", the future has come, starting from the present | new mode of it consumption, FOD billing on demand
Negative remainder problem
负数取余问题
5g R17 standard is frozen. What does it say?
[5gc] Introduction to three SSC (session and service continuity) modes
Business opportunities with an annual increase of 3billion - non cage eggs or a new blue ocean for export to ASEAN
The execution results of i+=2 and i++ i++ under synchronized are different
API call display, detailed API of Taobao, tmall and pinduoduo commodity pages, and return of APP side original data parameters
BannerViewPager
VC hacon joint programming genimage3extern writeimage
easycode一键生成插件自定义模板
[image denoising] image denoising based on regularization with matlab code
Market scale forecast and future competitive trend outlook report of China's plastic and cosmetic industry 2022-2028