How does linux-kernel read the proc / pid file?

How and where linux-kernel reads the proc / pid file, which shows all the processes in the system. I found linux-source-2.6.31 / fs / proc / There are files here, but this is hard to understand because it is really complicated. Maybe someone knows how this works?

+5
source share
3 answers

/ proc is a pseudo file system, which means its contents are not a “real” file. Instead, the content is a representation of the internal data structures of the kernel. Therefore, the kernel does not need to read them - it can already directly access the data.

/proc (, ), ps, () , . , , .

+8

.

, proc_pid_readdir() fs/proc/base.c pid /proc. :

ns = filp->f_dentry->d_sb->s_fs_info;
iter.task = NULL;
iter.tgid = filp->f_pos - TGID_OFFSET;
for (iter = next_tgid(ns, iter);
     iter.task;
     iter.tgid += 1, iter = next_tgid(ns, iter)) {
    filp->f_pos = iter.tgid + TGID_OFFSET;
    if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
        put_task_struct(iter.task);
        goto out;
    }
}
+3

/proc, , , , ps /proc /pids..

Linux ProcFs Linux Proc

+1

All Articles