Better access to "/proc" ?

Better access to "/proc" ?

Post by Tvrtko A. Ursuli » Sat, 16 Mar 2002 21:43:34



Being reluctant to use /proc/<pid> to gather process data because of !speed
and overhead (proc-fs does snprintf, userland does sscanf), I started
writting my own kernel module (misc device).

Everything was great, I "stole" code from proc-fs, made my own little
struct with interesring fields, and wrote an ioctl for my misc driver to
fill that struct.

But... when I tried to insmod then I realized that two calls used by
proc-fs are not exported for module use. access_process_vm() and mmput().
So... is there a way to do this without patching the kernel? If not, maybe
I'll still use my module because that two calls are only required for
cmdline field.

Or maybe did I failed to notice an already written interface to access
desired data ???

Thanks for any hints!

 
 
 

Better access to "/proc" ?

Post by Tvrtko A. Ursuli » Sat, 16 Mar 2002 23:21:13



> So... is there a way to do this without patching the kernel? If not, maybe
> I'll still use my module because that two calls are only required for
> cmdline field.

Now I see that mmput() is also used to inspect process memory usage. From
fs/proc/array.c :

int proc_pid_status(struct task_struct *task, char * buffer)
{
        char * orig = buffer;
        struct mm_struct *mm;

        buffer = task_name(task, buffer);
        buffer = task_state(task, buffer);
        task_lock(task);
        mm = task->mm;
        if(mm)
                atomic_inc(&mm->mm_users);
        task_unlock(task);
        if (mm) {
                buffer = task_mem(mm, buffer);
                mmput(mm);
        }

Why is that mmput(mm) ??
What about just atomic_dec(&mm->mm_users) ??

Thanks!