访问 /proc 时触发哪个内核函数?

Which kernel function is triggered when /proc is accessed?

哪个函数负责 /proc 创建的主要逻辑?

我必须实现这个问题中提到的行为。

我想有一个循环遍历任务列表并创建相应条目的函数。我正在寻找类似的东西。

我寻找使用 create_proc_entry() 函数的函数,但我找不到突出的东西。

实际上每个模块都自己处理它的 proc 文件。使用 Linux' 源代码,您可以 grep 查找 proc 中的各个文件名。这样你应该能够找到感兴趣的函数的位置。

I suppose there is a function that loops through the task list and creates the corresponding entries. I am looking for something like that.

proc_pid_readdir() fs/proc/base.c 中的函数正是这样做的。

for 循环会创建所有 /proc/PID 条目。 iter.task是当前task_struct指针

int proc_pid_readdir(struct file *file, struct dir_context *ctx)
{
    /*
     .
     .
     .
      */
    for (iter = next_tgid(ns, iter);
         iter.task;
         iter.tgid += 1, iter = next_tgid(ns, iter)) {
        char name[PROC_NUMBUF];
        int len;

        if (!has_pid_permissions(ns, iter.task, 2))
            continue;

        len = snprintf(name, sizeof(name), "%d", iter.tgid);
        ctx->pos = iter.tgid + TGID_OFFSET;
        if (!proc_fill_cache(file, ctx, name, len,
                     proc_pid_instantiate, iter.task, NULL)) {
            put_task_struct(iter.task);
            return 0;
        }
    }
    ctx->pos = PID_MAX_LIMIT + TGID_OFFSET;
    return 0;
}