当前位置:网站首页>系统 日志
系统 日志
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);
}边栏推荐
- Fault analysis | a case of MySQL remote slave database replication delay
- io. seata. common. exception. FrameworkException: can not connect to services-server.
- Standard library template learning introduction original
- What is data driven
- 【图像去噪】基于正则化实现图像去噪附matlab代码
- Cookie & session & kaptcha verification code
- Jenkins各配置选项介绍原创
- 攻防世界(web篇)---supersqli
- China's asset management market demand and future competitive trends outlook report 2022-2028
- Can't understand kotlin source code? Starting with the contracts function~
猜你喜欢

Reading small program based on wechat e-book graduation design (4) opening report

How do I create my own appender in log4j- How to create my own Appender in log4j?

First build green, then build city

基于微信电子书阅读小程序毕业设计毕设作品(7)中期检查报告

负数取余问题
![[SQL] MySQL query statement execution sequence analysis](/img/e0/6c55b798b5debfc780fb51498455ab.jpg)
[SQL] MySQL query statement execution sequence analysis

Dacom G150双模耳机,为爱发声,呵护孩子听力健康成长

vc hacon 联合编程 GenImage3Extern WriteImage

Negative remainder problem

RT thread simulator builds lvgl development and debugging environment
随机推荐
Native servlet - upload & download of files
3D object detection
94. 解析网页中的内容
94. analyze the content in the web page
Equipment management - borrowing / returning module interface code
Reading small program graduation design based on wechat e-book (5) assignment
Module 8 fonctionnement
Reading applet based on wechat e-book graduation design (2) applet function
no available service ‘null‘ found, please make sure registry config correct
How does Eldon's ring of the law get lune quickly? Introduction to the fastest and safest method for obtaining lune
The solution of BiliBili video list name too long and incomplete display
腾讯云TDP-virt-viewer win客户端的软件使用
META-INF、WEB-INF分别是什么?
负数取余问题
What is data driven
asp. Net using JSON to interact with API data
Dacom G150双模耳机,为爱发声,呵护孩子听力健康成长
基于微信电子书阅读小程序毕业设计毕设作品(4)开题报告
攻防世界(web篇)---supersqli
io. seata. common. exception. FrameworkException: can not connect to services-server.