'ps' info in program?

'ps' info in program?

Post by dkris.. » Fri, 07 Feb 1997 04:00:00



I would like to know how one can get the information available from the
'ps' utility within a program.
Assume that the program that requires this info is running as the
super-user (ie. a set-UID program).

I would much appreciate the help!! Thanx.
--
--------------------
Dileep Krishna

 
 
 

'ps' info in program?

Post by bspiko » Fri, 07 Feb 1997 04:00:00


Under Sun Solaris 2.x there is a file system that has this information.  I
do not know if IBM has implemented this feature yet.  Otherwise you can
either run the ps command as a child process and redirect it's output back
into your program, or you can find out where in physical memory the
information is kept and mmap it into your address space. (Since you are
super-user)


> I would like to know how one can get the information available from the
> 'ps' utility within a program.
> Assume that the program that requires this info is running as the
> super-user (ie. a set-UID program).

> I would much appreciate the help!! Thanx.
> --
> --------------------
> Dileep Krishna



 
 
 

'ps' info in program?

Post by Walsh Brow » Fri, 07 Feb 1997 04:00:00



> I would like to know how one can get the information available from the
> 'ps' utility within a program.
> Assume that the program that requires this info is running as the
> super-user (ie. a set-UID program).

> I would much appreciate the help!! Thanx.
> --
> --------------------
> Dileep Krishna


Howdy,

Within AIX 4.1 (and maybe even 3.2) you can get process table entries
via a C program via the getprocs() subroutine.  Here is a snippet from
the Info man page:

  #include <procinfo.h>
  #include <sys/types.h>

  int getprocs (ProcessBuffer, ProcessSize, FileBuffer, FileSize,
                                                  IndexPointer, Count);

  struct procsinfo *ProcessBuffer;
  int ProcessSize;
  struct fdsinfo *FileBuffer;
  int FileSize;
  pid_t *IndexPointer;
  int Count;

where:

ProcessBuffer  -->  Specifies the starting address of an array of
procsinfo structures to be filled in with process table entries. If a
value of NULL is passed for this parameter, the getprocs subroutine
scans the process table and sets return values as normal, but no process
entries are retrieved.

ProcessSize  -->  Specifies the size of a single procsinfo structure.

FileBuffer  -->   Specifies the starting address of an array of fdsinfo
structures to be filled in with per-process file descriptor information.
If a value of NULL is passed for this parameter, the getprocs subroutine
scans the process table and sets return values as normal, but no file
descriptor entries are retrieved.

FileSize  --> Specifies the size of a single fdsinfo structure.

IndexPointer --> Specifies the address of a process identifier which
indicates the required process table entry (this does not have to
correspond to an existing process). A process identifier of zero selects
the first entry in the table. The process identifier is updated to
indicate the next entry to be retrieved.

Count  --> Specifies the number of process table entries requested.

This returns the contents of the process table internally to your C
program thus avoiding the menagerie of having to deal with pipes and
other IPC toys.  You have to look at procinfo.h to get determines which
members of each procsinfo structure that you want to look at.  (also
make sure that you use procsinfo (with and 's') and not procinfo
(without an 's') to feed getprocs() or it will balk.

Info will tell you more.

I hope this helps.

                                                        -- Walsh


 
 
 

'ps' info in program?

Post by A. Baner » Sat, 08 Feb 1997 04:00:00


: I would like to know how one can get the information available from the
: 'ps' utility within a program.
: Assume that the program that requires this info is running as the
: super-user (ie. a set-UID program).

: I would much appreciate the help!! Thanx.
: --
: --------------------
: Dileep Krishna

Try using 'system()', which would let you actually run the command.
'man system' for more info.

Otherwise, you can get info. on processes from files in the /proc
directory (I think).