有名管道程式碼
有名管道寫端程式碼
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<strings.h>
#include<signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#define fifo_name1 "./fifo1"
// int mkfifo(const char *pathname, mode_t mode);
void print_err(char *estr)
{
perror(estr);
exit;
}
void signal_fun(int signo)
{
remove(fifo_name1);
exit(-1);
}
int main(){
char buf[128]={0};
int fd= -1;
int ret=-1;
ret = mkfifo(fifo_name1 ,0664);
//huliecuwu
if (ret==-1&&errno!=EEXIST)print_err("mkfifo fail");
fd=open(fifo_name1 ,O_WRONLY);
if (fd==-1)print_err("open fail");
signal(SIGINT,signal_fun);
while(1){
bzero(buf,sizeof(buf));
scanf("%s",buf);
write(fd,buf,sizeof(buf));
}
return 0;
}
讀端程式碼
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<strings.h>
#include<signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#define fifo_name1 "./fifo1"
// int mkfifo(const char *pathname, mode_t mode);
void print_err(char *estr)
{
perror(estr);
exit;
}
void signal_fun(int signo)
{
remove(fifo_name1);
exit(-1);
}
int main(){
char buf[128]={0};
int fd= -1;
int ret=-1;
ret = mkfifo(fifo_name1 ,0664);
//huliecuwu
if (ret==-1&&errno!=EEXIST)print_err("mkfifo fail");
fd=open(fifo_name1 ,O_RDONLY);
if (fd==-1)print_err("open fail");
signal(SIGINT,signal_fun);
while(1){
bzero(buf,sizeof(buf));
read(fd,buf,sizeof(buf));
printf("data:%s\n",buf);
}
return 0;
}
相關文章
- 有名管道的實現
- Linux系統程式設計—有名管道Linux程式設計
- Linux程式間通訊②:有名管道FIFOLinux
- 3|程式間通訊--有名管道學習筆記筆記
- 無名管道和有名管道的概念與實現
- Linux系統程式設計(11)——程式間通訊之有名管道Linux程式設計
- 兩個有名管道實現qq通訊
- java 管道流程式碼示例Java
- 使用DOS管道的程式碼片段
- 程式間通訊系列--管道
- Laravel 路由管道原始碼分析Laravel路由原始碼
- 程式間通訊(一)管道
- linux系統程式設計之管道(一):匿名管道(pipe)Linux程式設計
- linux系統程式設計之管道(三):命令管道(FIFO)Linux程式設計
- C# 管道式程式設計C#程式設計
- linux系統程式設計之管道(二):管道讀寫規則Linux程式設計
- PHP多程式程式設計(2):管道通訊PHP程式設計
- Linux 的程式間通訊:管道Linux
- linux 程式間通訊之管道Linux
- linux程式間通訊--管道(PIPE & FIFO)Linux
- 溫故之.NET程式間通訊——管道
- 【IPC程式間通訊之二】管道PipeC程式
- Swoole 原始碼分析——基礎模組之 Pipe 管道原始碼
- 程式間通訊——POSIX 有名訊號量與無名訊號量
- angular 管道Angular
- redis管道Redis
- 管道pipe
- 自己動手實現 Shell 多程式管道符
- 利用windows api實現程式通訊(命名管道)WindowsAPI
- Linux系統程式設計之匿名管道Linux程式設計
- 程式設計優化之管道資料流程式設計優化
- 演算法鏈與管道(上):建立管道演算法
- 速度不夠,管道來湊——Redis管道技術Redis
- 介紹 Linux 中的管道和命名管道Linux
- 【linux】系統程式設計-1-程式、管道和訊號Linux程式設計
- LLinux系統程式設計(10)——程式間通訊之管道Linux程式設計
- Go的程式設計模式一-管道PipelineGo程式設計設計模式
- Channel(管道)- 《Go 專家程式設計》筆記提要Go程式設計筆記