管道实现ps -aux | grep a.out
来源:互联网 发布:域名为什么收费 编辑:程序博客网 时间:2024/06/06 01:57
/************************************************************************* * File Name: ps_aux.c * Author: lixiaogang * Mail: 2412799512@qq.com * Created Time: 2017年06月08日 星期四 21时13分08秒 ************************************************************************/#include<stdio.h>#include<stdlib.h>#include<string.h>#include<sys/types.h>#include<fcntl.h>#include<unistd.h>void sys_err(const char *str,int num){ perror(str); exit(num);}int main(int argc,char *argv[]){ int fd[2]; pid_t pid; if(pipe(fd) != 0){ sys_err("pipe",-1); } pid = fork(); if(pid < 0){ sys_err("fork",-1); }else if(pid == 0){ //ps -aux | grep a.out close(fd[0]); dup2(fd[1],STDOUT_FILENO); close(fd[1]); execlp("ps","ps","aux",NULL); return -3; } pid = fork(); if(pid < 0){ sys_err("fork",-1); } else if(pid == 0){ close(fd[1]); dup2(fd[0],STDIN_FILENO); close(fd[0]); execlp("grep","grep","a.out",NULL); } wait(NULL); wait(NULL); close(fd[0]); close(fd[1]); return 0;}
阅读全文
0 0
- 管道实现ps -aux | grep a.out
- ps -aux|grep 详细信息
- ps -aux|grep 详细信息
- ps aux|grep 详细信息
- ps -aux|grep 详细信息
- ps aux|grep
- ps -aux | grep 详细信息
- ps -aux|grep 详细信息
- ps -aux|grep 详细信息
- ps -aux|grep 详细信息
- ps aux | grep xxx
- ps -aux|grep 详细信息
- ps aux|grep xxx
- ps aux | grep 命令小结
- ps aux|grep xxx详解
- 使用ps aux|grep ×查找进程
- ps aux | grep nginx kill -9 pid
- linux命令ps aux|grep xxx详解
- 洛谷P3258 [JLOI2014]松鼠的新家
- 数据结构封装之《LinkList单向链表》
- POJ 1949 Chores 笔记
- javascript中的内置类型
- 《Python编程入门经典》笔记
- 管道实现ps -aux | grep a.out
- 双向链表
- baidu
- 欢迎使用CSDN-markdown编辑器
- python-打开文件与读写文件
- 母牛的故事(蓝桥杯)
- 《Python网络数据采集》学习中遇到的问题
- Python安装scipy,beautifulsoup,Scrapy
- 动态符号链接的细节