System Call - ps command-- question

System Call - ps command-- question

Post by roy » Sat, 19 May 2001 20:05:59



hi all,

i'm writing a program to find out what processes my solaris server is
running, and handle the information obtained.

does anyone know how i can use system call in my program for the ps -ef
command?
or does anyone have the source/alt source for the ps -ef command?

thx all for yr help,
roy

 
 
 

System Call - ps command-- question

Post by Nithyanandha » Sat, 19 May 2001 20:23:26



> hi all,

> i'm writing a program to find out what processes my solaris server is
> running, and handle the information obtained.

> does anyone know how i can use system call in my program for the ps -ef
> command?
> or does anyone have the source/alt source for the ps -ef command?

Open and read the directory entries in " /proc ".   Except dot. and
dot.dot., everything else is a process.
I hope , you know how to open/read/close the directories

--Nithyanand.

 
 
 

System Call - ps command-- question

Post by Arthur H. Gol » Sun, 20 May 2001 02:36:08



> hi all,

> i'm writing a program to find out what processes my solaris server is
> running, and handle the information obtained.

> does anyone know how i can use system call in my program for the ps -ef
> command?
> or does anyone have the source/alt source for the ps -ef command?

Why not use `popen()'?

   FILE * ps_results = popen( "ps -ef", "r" );
   if ( ! ps_results ) {
      /* deal with the situation where the command failed */
   }
   else {
      int pclose_rslt;
      /* do whatever you need to; ps_results is treated just
       * like a normal file stream, with the exception that
       * when you're done you do a
       */
      pclose_rslt = pclose( ps_results );
      if ( pclose_rslt < 0 ) {
         /* some error occurred, deal with it */
      }
   }

HTH,
--ag

--
Artie Gold, Austin, TX  (finger the cs.utexas.edu account for more info)

--
I am looking for work. Contact me.

 
 
 

System Call - ps command-- question

Post by roy » Sun, 20 May 2001 12:39:01


currently, im considering using either #1 reading from /proc #2 using popen
#3 system call.
the advantage of system call is that the structure of the data of the ps- ef
is returned. that way, i would not have to parse the data. but of course
this is a more difficult way to do it.

roy




> > hi all,

> > i'm writing a program to find out what processes my solaris server is
> > running, and handle the information obtained.

> > does anyone know how i can use system call in my program for the ps -ef
> > command?
> > or does anyone have the source/alt source for the ps -ef command?

> Why not use `popen()'?

>    FILE * ps_results = popen( "ps -ef", "r" );
>    if ( ! ps_results ) {
>       /* deal with the situation where the command failed */
>    }
>    else {
>       int pclose_rslt;
>       /* do whatever you need to; ps_results is treated just
>        * like a normal file stream, with the exception that
>        * when you're done you do a
>        */
>       pclose_rslt = pclose( ps_results );
>       if ( pclose_rslt < 0 ) {
>          /* some error occurred, deal with it */
>       }
>    }

> HTH,
> --ag

> --
> Artie Gold, Austin, TX  (finger the cs.utexas.edu account for more info)

> --
> I am looking for work. Contact me.

 
 
 

System Call - ps command-- question

Post by Nils O. Sel?sda » Tue, 22 May 2001 21:21:08



Quote:> currently, im considering using either #1 reading from /proc #2 using
popen
> #3 system call.
> the advantage of system call is that the structure of the data of the ps-
ef
> is returned. that way, i would not have to parse the data. but of course
> this is a more difficult way to do it.

I wouldnt call #2 a system call, it just execs a process that do the parsing
of /proc for you, a system call is
usually a call to the kernel based on a number(number to the function you
want to access).
 
 
 

System Call - ps command-- question

Post by Ragnar Hojland Espino » Wed, 23 May 2001 14:03:49



> does anyone know how i can use system call in my program for the ps -ef
> coms anyone have the source/alt source for the ps -ef command?

You can find the source for procps at http://www.cs.uml.edu/~acahalan/procps/
While it is for linux and not for solaris, you may find it useful or at least
 instructive on how to handle the proc / ps.

--
____/|  Ragnar H?jland      Freedom - Linux - OpenGL |    Brainbench MVP
\ o.O|  PGP94C4B2F0D27DE025BE2302C104B78C56 B72F0822 | for Unix Programming
 =(_)=  "Thou shalt not follow the NULL pointer for  | (www.brainbench.com)
   U     chaos and madness await thee at its end."

 
 
 

1. help with system call-- ps command

hi all,

i'm writing a program to find out what processes my solaris server is
running, and handle the information obtained.

does anyone know how i can use system call in my program for the ps -ef
command?
or does anyone have the source/alt source for the ps -ef command?

thx all for yr help,
roy

2. ne2000 compatible

3. How I could add a new system call to linux or modify a system calls

4. POP3 and Linux

5. How to use open system call in a new system call

6. gcc 2.95.2 and gdb 5.0 and threads?

7. "Interrupted system call" at "low level" - system calls

8. UMSDOS working great...why so little mention?

9. ps system call?

10. I have uploaded the system call based ps

11. C system call to check for a process by name (something similar to ps)

12. implementation of 'ps' using C system calls.

13. System call to mimic ps?