Linux 进程间通讯之创办无名管道和读写无名管道

Linux 进程间通讯之创建无名管道和读写无名管道

Linux进程间通讯的方式:

1.     管道(pipe)和有名管道(FIFO).

2.     信号(signal)

3.     消息队列

4.     共享内存

5.     信号量

6.     套接字(socket)

 

 

管道通讯:

无名管道:pipe()函数创建,int
pipe(int 
filedis[2]),
当管道建立时有两个文件描述符,filedis[0]用于读管道,filedis[1]用于写管道。关闭管道,仅需将两个文件描述符关闭即可。

 

创建无名管道pipe()

#include <unistd.h>

#include <stdio.h>

 

int main(){

         intpipe_filed[2];

         if(pipe(pipe_filed)<0){

                   printf("pipecreate failed.\n");

                   return-1;

         }

         else{

                   printf("pipecreate successfully.\n");

                  close(pipe_filed[0]);                            //<span st

Linux 进程间通讯之创办无名管道和读写无名管道

相关文章:

你感兴趣的文章:

标签云: