进程通信 (命名管道 单向通信)
来源:互联网 发布:西南大学官网网络教育 编辑:程序博客网 时间:2024/06/07 06:01
client.c: 1 #include<stdio.h> 2#include<stdlib.h> 3#include<string.h> 4#include<sys/stat.h> 5#include<sys/types.h> 6#include<unistd.h> 7#include<fcntl.h> 8#define _PATH_ "./tmp" 9#define SIZE 100 10int main() 11 { 12 if(mkfifo(_PATH_,0666|S_IFIFO)<0) 13 { 14 perror("mkfifo"); 15 return -1; 16 } 17 intfd=open(_PATH_,O_WRONLY); 18 if(fd<0) 19 { 20 perror("open"); 21 return -1; 22 } 23 char buf[SIZE]; 24 memset(buf,'\0',SIZE); 25 while(1) 26 { 27 scanf("%s",buf); 28 write(fd,buf,strlen(buf)); 29 } 30 close(fd); 31 return 0; 32 } server.c: 1 #include<stdio.h>2 #include<stdlib.h>3 #include<string.h>4 #include<sys/stat.h>5 #include<sys/types.h>6 #include<unistd.h> 7#include<fcntl.h> 8#define _PATH_ "./tmp" 9#define SIZE 100 10int main() 11 { 12 intfd=open(_PATH_,O_RDONLY); 13 if(fd<0) 14 { 15 perror("open"); 16 return -1; 17 } 18 char buf[SIZE]; 19 while(1) 20 { 21 22 memset(buf,'\0',SIZE); 23 read(fd,buf,sizeof(buf)); 24 printf("%s\n",buf); 25 } 26 close(fd); 27 return 0; 28 } Makefile: 1.PHONY:all 2 all:client server 3 server:server.c 4 gcc -o $@ $^ 5client:client.c 6 gcc -o $@ $^ 7.PHONY:clean 8clean: 9 rm -f client server tmp
本文出自 “liveyoung” 博客,转载请与作者联系!
0 0
- 进程通信 (命名管道 单向通信)
- C#命名管道进程通信(一单向)
- 进程通信(管道 单向通信)
- 命名管道进程通信
- linux进程通信(命名管道)
- linux进程间通信(命名管道)
- 进程间通信--命名管道(fifo)
- 进程间通信(2):命名管道
- 进程间通信---命名管道
- 进程间通信---命名管道
- 进程通信系列-命名管道
- 进程间通信--命名管道
- 进程间通信----命名管道
- 进程间通信命名管道
- 进程通信--命名管道(FIFO)
- 【Linux】 进程通信--命名管道
- 进程间通信-命名管道
- unity3D 命名管道 进程通信
- memmove函数实现2
- 创建一个字符串数组,总共5个元素,每个元素最多保存30个字符,写一个函数排序整个数组。
- c语言实现动态顺序表
- 实习杂记(22)being added, but it already has a parent
- 进程通信(管道 单向通信)
- 进程通信 (命名管道 单向通信)
- 进程通信(消息队列)
- bochs配置文件最简单的例子
- 进程通信(信号量)
- 进程通信(共享内存)
- 线程的创建、终止、等待
- RxJava操作符(02-创建操作)
- 分离线程
- Angular2入门——(4)为模板应用样式