《Linux程序设计》读书笔记:进程间通信:管道
2009-06-02 00:10
232 查看
popen与pclose
#include <stdio.h>
函数原型如下:
FILE *popen(const char *command, const char *open_mode);
int pclose(FILE *stream_to_close);
popen函数允许一个程序将另一个程序作为新进程来启动,并可以传递数据给它或者通过它接收数据。command字符串是要运行的程序名和相应的参数。open_mode必须是“r”或者“w”。
例子:
FILE *read_fp;
read_fp = popen("uname -a","r");
pclose(read_fp);
pipe调用
#include<unistd.h>
pipe函数的原型如下:
int pipe(int file_descriptor[2]);
数据从file_descriptor[1]写入,从 file_descriptor[0]读取。
例子:
int data_processed;
int file_pipes[2];
const char some_data[]="123";
char buffer[1024];
data_processed = write(file_pipes[1], some_data, strlen(some_data));
data_processed = read(file_pipes[0], buffer,1024);
#include <unistd.h>
int dup(int file_descriptor);
int dup2(int file_descriptor_one, int file_descriptor_two);
#include <stdio.h>
函数原型如下:
FILE *popen(const char *command, const char *open_mode);
int pclose(FILE *stream_to_close);
popen函数允许一个程序将另一个程序作为新进程来启动,并可以传递数据给它或者通过它接收数据。command字符串是要运行的程序名和相应的参数。open_mode必须是“r”或者“w”。
例子:
FILE *read_fp;
read_fp = popen("uname -a","r");
pclose(read_fp);
pipe调用
#include<unistd.h>
pipe函数的原型如下:
int pipe(int file_descriptor[2]);
数据从file_descriptor[1]写入,从 file_descriptor[0]读取。
例子:
int data_processed;
int file_pipes[2];
const char some_data[]="123";
char buffer[1024];
data_processed = write(file_pipes[1], some_data, strlen(some_data));
data_processed = read(file_pipes[0], buffer,1024);
#include <unistd.h>
int dup(int file_descriptor);
int dup2(int file_descriptor_one, int file_descriptor_two);
相关文章推荐
- 《Linux程序设计》--读书笔记---第十三章进程间通信:管道
- 《Linux程序设计》--读书笔记---第十三章进程间通信:管道
- 进程间通信:1.管道——读书笔记[Linux程序设计大全]
- 《Linux程序设计》——进程间通信:管道
- Linux程序设计笔记(第13章 进程间通信:管道)
- 进程间通信--管道
- 进程间通信之管道,消息队列,共享内存
- 进程间通信之管道
- Linus进程间通信(一)管道、命名管道的原理及实现
- 进程间通信之匿名管道
- 进程间通信之管道
- 进程间通信之管道
- 进程间通信——管道
- 管道实现进程间通信
- WINDOWS API 进程间通信,管道(PIPE),Remoting技术
- 进程间通信-管道
- 进程间通信_1_管道
- Linux进程间通信--进程,信号,管道,消息队列,信号量,共享内存
- 进程间通信IPC之--无名管道(pipe)和有名管道(fifo)
- 进程间通信之管道通信