socketpair 使用
来源:互联网 发布:锤子大爆炸软件下载 编辑:程序博客网 时间:2024/06/14 18:29
#include <stdio.h> #include <sys/socket.h>#include <sys/types.h>int main(){ int sync_fds[2]; if(socketpair(AF_UNIX, SOCK_STREAM, 0, sync_fds)){ perror("socketpair failed...\n"); return 0; } int child_pid = fork(); if(child_pid == -1){ perror("fork failed ...\n"); close(sync_fds[0]); close(sync_fds[1]); return 0; } if(child_pid){ close(sync_fds[0]); char buff; while(1){ sleep(1); send(sync_fds[1], "C", 1, MSG_NOSIGNAL); printf("parent: send c ....\n"); read(sync_fds[1], &buff, 1); printf("parent: read %s\n", &buff); } }else{ close(sync_fds[1]); char buff; while(1){ int read_ret = read(sync_fds[0], &buff, 1); printf("child read %s\n", &buff); send(sync_fds[0], "D", 1, MSG_NOSIGNAL); printf("child send d ...\n"); } } return 0;}
输出结果:
parent: send c ....child read Cchild send d ...parent: read Dparent: send c ....child read Cchild send d ...parent: read Dparent: send c ....child read Cchild send d ...parent: read D
阅读全文
0 0
- socketpair使用
- socketpair 使用
- socketpair的使用
- socketpair的使用
- socketpair的使用
- socketpair的使用
- socketpair的使用
- socketpair的使用
- socketpair的使用
- socketpair的使用
- socketpair
- socketpair
- socketpair
- socketpair
- socketpair
- socketpair
- socketpair
- socketpair
- 我的第一个hbulider项目
- hadoop集群小项目实践及遇到问题解决办法
- Systemd 入门教程:命令篇
- Virtualbox虚拟机Linux Guest的Additions安装方法
- 学习RGB配色,灰度图
- socketpair 使用
- 主线程等待子线程全部执行完成
- vsftpd客户端只能读取问题 553异常
- Chapter eighteen 嵌入式安卓浅谈
- 判断远程文件是否 存在
- aopalliance的简易理解
- yum puppet 安装
- android 旧版actionbar升级toolbar出现的问题
- 简单八皇后