yuvalle1 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am using this module inside a watchdog script, trying to count the number of processes/threads of a process name. When used on RedHat 7.3, everything went well. However, when I upgraded to RedHat enterprose 3.0, I get one line per process (the process that has Pid=Tgid on the /proc/pid/status file. Has anyone encountered this? is there an optional recommended module? Thanks Yuval

Replies are listed 'Best First'.
Re: Proc::ProcessTable
by edan (Curate) on Jul 06, 2004 at 10:07 UTC

    Shalom yuvalle1!

    I believe that the threads implementation in newer Linux kernels is different than in RH 7.3. In particular, separate threads will no longer show up as separate processes (as in, having a separate PID).

    I don't know of another way to count the threads of a process, but if I come across one, I'll let you know...

    Update: What kernel is it? (what does uname -r say?) If it's 2.6, you may be able to use the /proc/$$/task directory. (Thanks to theorbtwo and ambrus for CB info).

    --
    edan

      Hi edan! Thanks for your reply. The thread implementation had changed, but not that dramatically - each thread has its pid and has a directory in /proc, so I was hoping that this module will still function (in vain). It seems that there is a group_id for each thread that equals the pid of the thread that created it. It is interesting that ps for example can give all the threads when it is used with the -m flag. I guess it is not that hard to count it myself using the /proc data, but I don't feel like it :) The kernel version we are using here is 2.4.21-4.ELsmp Thanks again for your help! yuvalle1
Re: Proc::ProcessTable
by zentara (Cardinal) on Jul 06, 2004 at 12:48 UTC
    Yes, I've noticed this too. If you read the man page for ps, one of the switches is
    -m show all threads
    otherwise, all threads are combined under a single pid. I don't know whether Proc::ProcessTable takes this into account yet, but it's a resource hog to use; so you may be better off parsing ps -m yourself, or reading directly from /proc/pid.

    I'm not really a human, but I play one on earth. flash japh