About thread support in LibGTop (was Re: Gtop memory display of threaded apps...)



Simon Heaton <simon.heaton@softwareag.co.uk> writes:

> If we are talking Linux then the tread model is that each thread is
> implemented as a separate process. It is all based on the clone() system
> call I believe.

Hello guys,

this seems to be a frequently asked question ....

Yes, the problem has to do with the Linux kernel.

Currently, there is no way to get information about threads (meaning
something like "give me all threads of pid X") on Linux.

The thread model is implemented using the clone() system with CLONE_VM
(and maybe also CLONE_FS etc., not sure) which results in a new process
being created which shares the page tables with the parent process.

Normally, LibGTop uses the /proc filesystem to read its data on Linux,
but this has no support for threads.

Even worse, the kernel itself keeps no information about whether a process
is a cloned copy of another process.

However, it may be possible to get information about threads on a Linux
system nevertheless:

====[kernel/fork.c - copy_mm()====
        if (clone_flags & CLONE_VM) {
                mmget(current->mm);
                tsk->min_flt = tsk->maj_flt = 0;
                tsk->cmin_flt = tsk->cmaj_flt = 0;
                tsk->nswap = tsk->cnswap = 0;
                /*
                 * Set up the LDT descriptor for the clone task.
                 */
                copy_segments(nr, tsk, NULL);
                SET_PAGE_DIR(tsk, current->mm->pgd);
                return 0;
        }
====

If I understand this correctly, we can compare the `tsk->mm->pgd' pointers
of two processes to find out whether they're cloned copies (actually to find
out whether they run in the same memory space). This may also work for
file descriptors etc.

However, this must be done in kernel mode so I need to do some more work
on my experimental sysctl () based thing ....

                                   * * *

In general, information about threads is already on my todo list for
LibGTop 1.2. Most likely, I'll first implement this in the Solaris port
since Solaris has the best thread support of all systems that are
currently supported by LibGTop.

-- 
Martin Baulig - martin@home-of-linux.org - http://www.home-of-linux.org



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]