你好,游客 登录 注册 搜索
背景:
阅读新闻

用socketpair()进行进程间的全双工通讯

[日期:2013-12-01] 来源:Linux社区  作者:chengshuguang [字体:大 中 小]

用socketpair()进行进程间的全双工通讯

/*************************************************
*  description: use socketpair() to implete IPC(全双工的IPC)
*  author: chengshuguang
**************************************************/
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>

#define child "wo shi child fa lai de"
#define parent "wo shi parent fa lai de"

int main()
{
 int fd[2];
 int ret;
 ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);

 pid_t pid;
 pid = fork();
 printf("here\n");
 if(pid == 0)
 {
  char buf[20];
  close(fd[0]);
  read(fd[1],buf,20);
  printf("child: %s\n",buf);

  write(fd[1],child,sizeof(child));
  close(fd[1]);

 }
 else
 {
  char buf[20];
  close(fd[1]);
  write(fd[0],parent,sizeof(child));
  read(fd[0],buf,20);
  printf("parent: %s\n",buf);
  close(fd[0]);
 }
 
 sleep(10);


 return 0;
}

解决mini2440声卡全双工问题 实现同时录音及播放 http://www.linuxidc.com/Linux/2011-05/36718.htm

linux
相关资讯       socketpair  全双工通讯 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款