Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / 用socketpair()进行进程间的全双工通讯

用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 ");
 if(pid == 0)
 {
  char buf[20];
  close(fd[0]);
  read(fd[1],buf,20);
  printf("child: %s ",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 ",buf);
  close(fd[0]);
 }
 
 sleep(10);
 return 0;
}解决mini2440声卡全双工问题 实现同时录音及播放 http://www.linuxidc.com/Linux/2011-05/36718.htm