方法:输出结果的重定向
#include<unistd.h>
#include<fcntl.h>
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int fd;
fd=open("ps.out",O_WRONLY|O_CREAT|O_TRUNC,0644);
if(fd<0)
{
perror("open ps.out error");
exit(1);
}
dup2(fd,STDOUT_FILENO);//将stdout的文件描述符(值为1)指针指向fd,即实现输出的重定向
execlp("ps","ps","ax",NULL);
return 0;
}
此时,系统的进程信息打印到ps.out文件中