1,stderr和stdout是结合fprintf使用的
2,使用实例,可执行程序假设为my.exe
int main()
{
fprintf(stderr, "err!\n");
fprintf(stdout, "out!\n");
return 0;
}
//假设运行./my.exe,则屏幕上的打印为
err!
out!
//假设运行./my.exe >1.tx,将输出重定向到1.txt,则屏幕上的打印为
err!
//1.txt中的文件内容为
out!
综上所述stdout是可以打印到文件中的,而stderr只能打印到屏幕上
3,fprintf可以直接写入文件
FILE *fp = fopen(“log.log”, rw);
fprintf(fp,“test !!!\n”);
则输出直接打印到log.log文件中
4,atexit
入参是一个无返回值,无输入值的函数,函数原型
int atexit(void (**)(void) )
exit调⽤终⽌处理函数的顺序和atexit登记的顺序相反,先注册的函数后执行
5,signal函数
指定当前进程监控某信号量,函数原型
void(* signal(int sig,void(* func)(int)))(int);
void mu_proc(int s)
{
if(SIGINT == s)
printf("get signal SIGINT\r\n");
}
signal(SIGINT, my_proc);
SIGINT 由Interrupt Key产生,通常是CTRL+C或者DELETE。发送给所有ForeGround Group的进程