概述
io简化模型如下:
父进程
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 中有引用计数判断:
void 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的全部内容,希望文章能够帮你解决父子进程共享模式下的epoll_wait所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复