Linux C程式設計 - 管道pipe
在linux中,管道也是一種文件,只不過比較特殊,我們可以用pipe函數創建一個管道,其原型聲明如下:
#inlcude
int pipe(int fields[2]) ;
其實它相當於一個通訊緩衝區,fields[0]用來讀,fields[1]用來寫。在下面的例子中,建立一個管道作為通訊緩衝區,父進程創建了一個子進程,子進程通過管道的fields[1]描述符想管道中寫入一個字串,而父進程則利用管道的fields[ 0] 從管道中讀取這個字符串並顯示出來:
#include
#include
#include
#include
#includeh>
#include
#include
#define BUF_SIZ 255 v)
{
char buffer[BUF_SIZ + 1];
int fd[2];
// rece {
fprintf(stderr, "Usage: %s stringna", argv [0]);
exit(1);
}
// create pipe for communication fprintf(stderr, "Create pipe error: %sna", strerror( errno));
exit(1);
}
if ( fork() == 0 {
close(fd[0]);
printf("Child %ld write to pipena", getpid());
snprintf(buffer, BUF_SIZ, "%s", argv[1])); printf("Child % ld quit.na", getpid());
}
else // in parent process, fd[1]);
printf("Parent %ld read from pipena", getpid( ));
memset(buffer, '

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)