gpt4 book ai didi

linux - 为什么Linux内核函数filp_close中posix线程id可以为NULL?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:50:09 27 4
gpt4 key购买 nike

以下摘自linux内核:

/*
* "id" is the POSIX thread ID. We use the
* files pointer for this..
*/
int filp_close(struct file *filp, fl_owner_t id)

文档说id是posix线程id,应该是current->files

但是,我在 Linux 内核中发现了很多用法,例如acct_on ,将其用作 filp_close(filp, NULL)

我的问题是:

为什么在调用 filp_close 时可以接受 NULL?

参数 id 的目的是什么?

最佳答案

根据这个discussionfl_owner_t 的正式描述将是

A generic "file lock owner" value. This is set differently for different 
types of locks.

The POSIX file lock owner is determined by the "struct files_struct" in the
thread group.

Flock (BSD) locks, OFD locks and leases set the fl_owner to the
file description pointer.

但实际上这是不透明的指针

legacy typedef, should eventually go away

它指的是进程文件描述符表(struct files_struct)。

至于filp_close函数,只有fs/file.c源代码使用了非NULL的id参数。所有其他用户手动创建 filp(使用 filp_openfile_open_name)并将 id 作为 NULL 传递。

关于linux - 为什么Linux内核函数filp_close中posix线程id可以为NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32442521/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com