#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.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); }
//将输出屏幕内容保存到fd文件 dup2(fd,STDOUT_FILENO);
//执行系统命令 execlp("ps","ps","ax",NULL); perror("execlp error"); return 0; }
标签:ps,系统命令,dup2,C语言,fd,execlp,include From: https://www.cnblogs.com/powercool/p/16590923.html