SUMMARY: PROCFS limited to 256 entries

From: Brian K. Holman <bkh_at_lib1.byu.edu>
Date: Mon, 3 Apr 1995 07:58:26 -0600 (MDT)

I got no responses from the list so I assume no one cares about this but I'm
sending a summary anyway :-)

This was my question:
>I have created a program that reads the PROCFS and uses that information
>to build a process tree. It then kills the leaf nodes that have been idle
>for a certain amount of time.
>
>However, I have run into a snag. The /proc directory will only report 256
>entries [254 processes, (.), (..)]. Even if I have 500 active processes on
>the system, the maximum I can see in /proc is 256 using ls or the readdir
>system call.
>
>I tried to find a kernel parameter that I could change but without any
>success. Can anyone shed any light on this problem?

DEC support recommended the following:

>You may try the seekdir call or even getdirentries. The getdirentries call
>will fill as many dirent entries as available or you pass.

It looks like this system call will work but I still think it is a bug since
'ls' only reports the first 256 /proc entries as well.

Not completely satisfied, I poked through the OSF1 specific stuff in the top
source and came up with the following method for getting process table
entries that is fast and complete and bypasses the PROCFS altogether. The
man page table(2) has more information on the data structures, etc.

#include <sys/table.h>
#include <values.h>

int main()
{
        int nproc, idx1, idx2, ret;
        struct tbl_procinfo p_i[8];
        
        nproc = table(TBL_PROCINFO, 0, 0, MAXINT, 0);
        for (idx1=0; idx1<nproc; idx1 += 8)
        {
                ret = table(TBL_PROCINFO, idx1, (struct tbl_procinfo *)p_i, 8, sizeof(struct tbl_procinfo));
                for (idx2=0; idx2 < ret; idx2++)
                {
                            if ((p_i[idx2].pi_pid != 0) && (p_i[idx2].pi_status == PI_ACTIVE))
                                printf("PID %i %s\n",p_i[idx2].pi_pid,p_i[idx2].pi_comm);
                }
        }
}
-- 
+-----------------------------+--------------------------------------------+
| BRIAN K. HOLMAN             | E-Mail:               brian_holman_at_byu.edu |
| Programmer/Systems Analyst  | URL:        http://lib1.byu.edu/staff/bkh/ |
| Library Information Systems | Mail:           2330 HBLL, Provo, UT 84602 |
| Brigham Young University    | Phone:                      (801) 378-8162 |
+-----------------------------+--------------------------------------------+
Received on Mon Apr 03 1995 - 09:55:54 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:45 NZDT