当前位置:网站首页>Stderr and stdout related standard outputs and other C system APIs

Stderr and stdout related standard outputs and other C system APIs

2022-06-25 14:59:00 qq_ twenty-three million nine hundred and fifty-three thousand

1,stderr and stdout Is a combination of fprintf The use of
2, Using examples , The executable program is assumed to be my.exe

int main()
{
    
	fprintf(stderr, "err!\n");
	fprintf(stdout, "out!\n");
	return 0;
}
// Hypothetical operation ./my.exe, Then the print on the screen is 
err!
out!
// Hypothetical operation ./my.exe >1.tx, Redirect output to 1.txt, Then the print on the screen is 
err!
//1.txt The content of the file is 
out!

in summary stdout Can be printed to a file , and stderr Can only be printed to the screen
3,fprintf You can write directly to the file
FILE *fp = fopen(“log.log”, rw);
fprintf(fp,“test !!!\n”);
The output is printed directly to log.log In file
4,atexit
The input parameter is a no return value , Functions without input values , The function prototype
int atexit(void (**)(void) )
exit transfer ⽤ end ⽌ The order of processing functions and atexit Reverse order of registration , Register the function first and then execute
5,signal function
Specifies that the current process monitors a semaphore , The function prototype

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 from Interrupt Key produce , Usually CTRL+C perhaps DELETE. Send to all ForeGround Group The process of

原网站

版权声明
本文为[qq_ twenty-three million nine hundred and fifty-three thousand ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200514582207.html