io简化模型如下:
复制代码
1
2
3
4
5
6
7
8
9
10
父进程
bind
listen
fork
waitpid
子进程
epoll_ctrl add
epoll_wait
accept
epoll 手册中说道,关闭fd将自动从epoll中删除
close of an fd cause it to be removed from all epoll sets automatically
坑爹的是,父子进程共享端口的情况下,监听句柄对应的struct file 文件结构,引用计数将为2,若只在子进程中关闭fd,而不显示调用epoll_ctl 将改句柄监听删除, file 结构引用计数将无法减为0,将无法释放改句柄在epoll_wait 中的epoll sets;由于file->socket->tcp_sock 关系仍然保持着,tcp监听端口还存在着,若此时有tcp请求连接时,将还会唤醒子进程的epoll_wait,而无法处理导致而陷入死循环;
对应内核代码:
fs/open.c close->filp_close->fput->__fput->eventpoll_release
fput 中有引用计数判断:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16void fput(struct file *file) { if (atomic_long_dec_and_test(&file->f_count)) __fput(file); } void __fput(struct file *file) { ****** fsnotify_close(file); /* * The function eventpoll_release() should be the first called * in the file cleanup chain. */ eventpoll_release(file);
最后
以上就是难过柠檬最近收集整理的关于父子进程共享模式下的epoll_wait的全部内容,更多相关父子进程共享模式下内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复