首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

linux内核中的文件描述符(3)-fd的回收

2013-01-17 
linux内核中的文件描述符(三)--fd的回收 linux内核中的文件描述符(三)--fd的回收Kernel version:2.6.14CPU

linux内核中的文件描述符(三)--fd的回收

 linux内核中的文件描述符(三)--fd的回收

Kernel version:2.6.14

CPU architecture:ARM920T

Author:ce123(http://blog.csdn.net/ce123)

1.close函数

linux内核中的文件描述符(3)-fd的回收

上图说明了close(fd)的执行过程,主要包括两部分:释放文件描述符fd,关闭文件file。

//fs/file_table.cvoid fastcall fput(struct file *file){if (rcuref_dec_and_test(&file->f_count))__fput(file);}void fastcall __fput(struct file *file){struct dentry *dentry = file->f_dentry;struct vfsmount *mnt = file->f_vfsmnt;struct inode *inode = dentry->d_inode;might_sleep();fsnotify_close(file);/* * The function eventpoll_release() should be the first called * in the file cleanup chain. */eventpoll_release(file);locks_remove_flock(file);if (file->f_op && file->f_op->release)file->f_op->release(inode, file);//在这里调用release函数。在socket中即socket_close函数security_file_free(file);if (unlikely(inode->i_cdev != NULL))cdev_put(inode->i_cdev);fops_put(file->f_op);if (file->f_mode & FMODE_WRITE)put_write_access(inode);file_kill(file);file->f_dentry = NULL;file->f_vfsmnt = NULL;file_free(file);dput(dentry);mntput(mnt);}

热点排行