当前位置:网站首页>进程会计、进程时间、守护进程
进程会计、进程时间、守护进程
2022-06-12 19:35:00 【Lee Neo】
进程会计:acct()
会将消亡的进程信息记录到特定的文件当中;
进程时间:times()
统计进程的时间;

守护进程:
会话;
终端;
setsid();
守护进程的特征:
ppid=1;pid=sid=pgid;tty=?;

#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#define FNAME "/tmp/out"
static int daemonize(void)
{
int fd;
pid_t pid;
pid = fork();
if(pid <0)
{
perror("fork()");
exit(1);
}
if(pid >0)
exit(0);
fd = open("/dev/null", O_RDWR);
if(fd < 0)
{
perror("open()");
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;
if(daemonize())
exit(1);
fp = fopen(FNAME, "w");
if(fp == NULL)
{
perror("fopen()");
exit(1);
}
for(int i = 0; ; i++ )
{
fprintf(fp, "%d\n", i);
fflush(fp);
sleep(1);
}
exit(0);
}边栏推荐
- 5G R17标准冻结,主要讲了些啥?
- Detailed explanation of IO flow basic knowledge -- file and IO flow principle
- Exploration of a flexible injection scheme for istio sidecar
- review. JS ppt math formula cannot be displayed
- 94. 解析网页中的内容
- Liunx deploy Seata (Nacos version)
- Business opportunities with an annual increase of 3billion - non cage eggs or a new blue ocean for export to ASEAN
- Mode of most elements (map, sort, random, Boyer Moore voting method)
- A small case with 666 times performance improvement illustrates the importance of using indexes correctly in tidb
- In 2021, the global revenue of electro-optical modulator (EOM) is about USD 360.3 million, and it is expected to reach USD 704.4 million in 2028
猜你喜欢

Equipment management - borrowing and returning module 1
![[5gc] Introduction to three SSC (session and service continuity) modes](/img/98/6e08986269c5dc1f5ce192cdef3e9f.png)
[5gc] Introduction to three SSC (session and service continuity) modes

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

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

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

基于微信电子书阅读小程序毕业设计毕设作品(4)开题报告
![[digital ic/fpga] data accumulation output](/img/58/8d10e41a7bc837feba677f1e0b1ceb.png)
[digital ic/fpga] data accumulation output

Storage system overview

3D object detection

攻防世界(web篇)---supersqli
随机推荐
"As a service", the future has come, starting from the present | new mode of it consumption, FOD billing on demand
Mysql database experiment I data definition
Wechat e-book reading applet graduation design completion works (3) background function
Standard library template learning introduction original
Market development planning and investment prospect analysis report of Chinese government investment and financing platform 2022-2027
Research Report on current market situation and investment prospect of China's tobacco RFID industry 2022-2027
【图像去噪】基于正则化实现图像去噪附matlab代码
review.js ppt数学公式无法显示
RT-Thread 模拟器 simulator 搭建 LVGL 的开发调试环境
Reading small program based on wechat e-book graduation design (4) opening report
负数取余问题
什么是数据驱动
asp. Net using JSON to interact with API data
API call display, detailed API of Taobao, tmall and pinduoduo commodity pages, and return of APP side original data parameters
In 2021, the global revenue of chlorinated polyvinyl chloride (CPVC) was about $1809.9 million, and it is expected to reach $3691.5 million in 2028
What did 3GPP ran do in the first F2F meeting?
Mode of most elements (map, sort, random, Boyer Moore voting method)
基于微信电子书阅读小程序毕业设计毕设作品(3)后台功能
What are the third-party software testing organizations in Shanghai that share knowledge about software validation testing?
China's asset management market demand and future competitive trends outlook report 2022-2028