管道pipe
pipe是popen的底層函式
子程式呼叫 pipe3程式,傳給pipe3 管道的檔案描述符
pipe3對檔案描述符進行讀操作
實現不用程式之間的資料傳輸
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
int main(){
pid_t fork_result;
const char some_data[] = "123";
int file_pipes[2];
char buffer[BUFSIZ + 1];
int data_processed;
memset(buffer,'\0',sizeof(buffer));
if(pipe(file_pipes) == 0){
fork_result = fork();
//child thread
if(fork_result == 0){
sprintf(buffer,"%d",file_pipes[0]);
execl("pipe3","pipe3",buffer,(char *)0);
exit(0);
}else{
data_processed = write(file_pipes[1],some_data,strlen(some_data));
printf("%d - wrote %d bytes\n",getpid(),data_processed);
}
}
exit(0);
}
pipe3
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc,char *argv[]){
char buffer[BUFSIZ + 1];
int file_descriptor;
memset(buffer,'\0',sizeof(buffer));
sscanf(argv[1],"%d",&file_descriptor);
read(file_descriptor,buffer,BUFSIZ);
printf("get data:%s\n",buffer);
exit(0);
}
相關文章
- Linux中的pipe(管道)與named pipe(FIFO 命名管道)Linux
- 對於Pipe管道之愛 - jessfraz
- linux系統程式設計之管道(一):匿名管道(pipe)Linux程式設計
- linux程式間通訊--管道(PIPE & FIFO)Linux
- IPC實現機制(一)---pipe(匿名管道)
- 【IPC程式間通訊之二】管道PipeC程式
- 事件匯流排有個 pipe 管道方法事件
- Swoole 原始碼分析——基礎模組之 Pipe 管道原始碼
- Linux 核心最新高危提權漏洞:髒管道 (Dirty Pipe)Linux
- 在Linux中,管道(pipe)和重定向(redirection)的是什麼?Linux
- 管道函式及表函式的測試PIPELINED__PIPE ROW函式
- Broken pipe
- pipe函式使用函式
- Linux pipe功能Linux
- RMAN的PIPE介面
- EXP&IMP PIPE
- Python並行程式設計(九):多程式物件交換之pipe(管道)實現生產者-消費者模型Python並行行程程式設計物件模型
- 精讀《pipe operator for JavaScript》JavaScript
- PIPE函式的例子函式
- RMAN的PIPE介面(二)
- angular 管道Angular
- redis管道Redis
- Node Stream pipe的誕生
- How to recover from USB pipe errorsError
- java.net.SocketException: Broken pipeJavaException
- 演算法鏈與管道(上):建立管道演算法
- 速度不夠,管道來湊——Redis管道技術Redis
- 介紹 Linux 中的管道和命名管道Linux
- mongodb 聚合管道MongoDB
- 【linux】管道!!!Linux
- windows命名管道Windows
- Linux 管道Linux
- Linux管道Linux
- Oracle vs PostgreSQL Develop(19) - PIPE ROWOracleSQLdev
- 使用Pipe來執行RMAN命令
- oracle實驗-RMAN的PIPE介面Oracle
- Pandas - pandas.Series.pipe 函式函式
- 無名管道和有名管道的概念與實現