进程间通信 IPC

概念和技巧:

1.挂起并等会从多个源端的输入:select 和 poll

2.命名管道

3.共享内存

4.文件锁

5.信号量

6.IPC

 

select :允许进程挂起,并等待不止一个文件描述符的输入:

#include <sys/select.h>

/* According to earlier standards */
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

int ret=select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout);

void FD_CLR(int fd, fd_set *set);
int FD_ISSET(int fd, fd_set *set);
void FD_SET(int fd, fd_set *set);
void FD_ZERO(fd_set *set);

  nfds=需要监听的最大值fd+1

  readfds=等待从此集合包括的文件描述符到来的数据

  writefds=等待向这些文件描述符写数据的许可

  exceptfds=等待这些文件描述符操作的异常

  timeout=超过此事件后函数返回

ret: -1=错误,0=超时,num=满足需求的文件描述符数目。

posted @ 2022-01-10 23:48  愿得入睡  阅读(44)  评论(0)    收藏  举报