⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 whotofile.c

📁 介绍和编写和IO重定向的使用
💻 C
字号:
/* whotofile.c *	purpose: show how to redirect output for another program *	   idea: fork, then in the child, redirect output, then exec */#include	<stdio.h>main(){	int	pid ;	int	fd;	printf("About to run who into a file\n");	/* create a new process or quit */	if( (pid = fork() ) == -1 ){		perror("fork"); exit(1);	}	/* child does the work */	if ( pid == 0 ){		close(1);				/* close, */		fd = creat( "userlist", 0644 );		/* then open */		execlp( "who", "who", NULL );		/* and run	*/		perror("execlp");		exit(1);	}	/* parent waits then reports */	if ( pid != 0 ){		wait(NULL);		printf("Done running who.  results in userlist\n");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -