SUMMARY: Can anyone help with the table call ?

From: Eric Wyn Jones (01248-382407) <"Eric>
Date: Thu, 1 May 1997 12:04:33 +0100 (BST)

Original question.
 
 Hello,
        I'm trying to use the table system call to get a list of
 processes ( home brew ps -A)
 
 According to the man page for table :-
   ...
   The table() interface returns a count of the elements examined or updated.
   The id TBL_PROCINFO allows you to determine the actual number of elements
   in a table before requesting any data; call table() with lel set to zero
   (0) and nel to the maximum positive integer.
   ...
 
 
   The following returns the value 4096 on my Alpha 2100 running DU 4.0B
 
         n=table(TBL_PROCINFO,0,(char *)0 ,1073741823 , 0 );
         if (n == -1) {
                 perror("table error");
                 exit(1);
         }
 
   However it seems the entries in this table are indexed by pid and some
   pids are greater than 4096. In fact I can call table with indices up
   to 32767 without getting an error return and I get information returned
   for entries > 4096 .
 
   So my question is :- Is the first call to table to get number of elements
    incorrect or what ?

Reply 1: From: "John K. Peterson" <jkpeters_at_acs2.byu.edu>

If I'm not mistaken, that's the number of processes slots that's returned,
which has nothing to do with the pid's. That is, you can have 4096
processes active on your system but the pid's are still 1 <= pid <= 32767
The pid has nothing to do with the index into the proc table.
To find the number of *active* processes, which I think is what your
looking for, you have to scan the table and count the slots refer to
active process. I base that on what I've seen in the source code for
'top'.

=================================================================
Reply 2: From: Stuart Davidson <stuart.davidson_at_eurocontrol.be>

Entries in the process table are reused, so some entries are
empty and others 'in use'. If you make another table call:

table(TBL_PROCINFO, 0, proc_table, n, sizeof(procinfo_t));

Where proc_table is n sized array of procinfo_t.

You can then step through proc_table, the 'is use' entries will have
proc_table.pi_status != PI_EMPTY


Conclusion :

 Well I still say that I can INDEX the table from 1<n<32767 getting a
 SINGLE entry into a structure of procinfo_t and I get a VALID return
 even for indices > 4096 (the size of the table) and the information
 returned agrees with "ps" and is for the process whose pid=index !

  If I follow Stuart Davidson's directions and get n=4096 entries
  into a 4096 array of procinfo_t then when I scan the array I only
  find information for processes whose pid are less than 4096 and
  a lot of PI_EMPTY's !


 There's unix magic for you now !
 


 -----------------------------------------------------------------------
| Eric Wyn Jones, | |
| Information Services, | |
| University of Wales, Bangor | |
 -----------------------------------------------------------------------
Received on Thu May 01 1997 - 13:20:16 NZST

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