访问/proc时会触发哪个内核功能? [英] Which kernel function is triggered when /proc is accessed?

查看:90
本文介绍了访问/proc时会触发哪个内核功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Which function is responsible for main logic of /proc creation?

我必须实现此问题中提到的行为. /proc目录是否按请求动态生成?

I have to achieve the behaviour mentioned in this question. Is /proc directory generated dynamically per request?

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

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

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

I looked for the functions that uses create_proc_entry() function but i could not find something that stands out.

推荐答案

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

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()函数完全可以做到这一点.

proc_pid_readdir() function in fs/proc/base.c does exactly that.

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

That for loop creates all the /proc/PID entries. iter.task is the current task_struct pointer

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;
}

这篇关于访问/proc时会触发哪个内核功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆