Consistent ps/top output format

B

Bart Van der Donck

Hello,

I have written a Perl script to store and interpret the output of the
unix 'ps'-command. It works well on my machine (FreeBSD 6.2.), but it
doesn't work on a few other unix variants that I tested.

I came to the conclusion that the output format is the culprit. This
appears to differ across ps/top variants on several OS-es, even with
the command line options mentioned in the docs.

Is there any way to get the output of "ps" (or "top -b") into a
reliable consistent format ?

Thanks,
 
U

Uri Guttman

BVdD> I have written a Perl script to store and interpret the output of the
BVdD> unix 'ps'-command. It works well on my machine (FreeBSD 6.2.), but it
BVdD> doesn't work on a few other unix variants that I tested.

BVdD> I came to the conclusion that the output format is the culprit. This
BVdD> appears to differ across ps/top variants on several OS-es, even with
BVdD> the command line options mentioned in the docs.

BVdD> Is there any way to get the output of "ps" (or "top -b") into a
BVdD> reliable consistent format ?

use a module. Sys::Info covers bsd, linux and winblows

uri
 
B

Bart Van der Donck

Uri said:
  BVdD> I have written a Perl script to store and interpret the output of the
  BVdD> unix 'ps'-command. It works well on my machine (FreeBSD 6.2.), but it
  BVdD> doesn't work on a few other unix variants that I tested.

  BVdD> I came to the conclusion that the output format is the culprit.This
  BVdD> appears to differ across ps/top variants on several OS-es, evenwith
  BVdD> the command line options mentioned in the docs.

  BVdD> Is there any way to get the output of "ps" (or "top -b") into a
  BVdD> reliable consistent format ?

use a module. Sys::Info covers bsd, linux and winblows

Thanks - I've looked into it, but the information returned by
Sys::Info is too general for me. The script should detect the 20 most
CPU-intensive processes ("ps -aux" or "top -b" on FreeBSD), e.g.:

PID USER THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
978 root 1 8 -20 5636K 2964K nanslp 18.2H 0.10% perl
8003 bind 1 4 20 28012K 1892K kqread 452:24 0.00% named
1019 root 1 4 -15 6172K 1332K sbwait 279:27 0.00% perl
...
 
J

J. Gleixner

Bart said:
Thanks - I've looked into it, but the information returned by
Sys::Info is too general for me. The script should detect the 20 most
CPU-intensive processes ("ps -aux" or "top -b" on FreeBSD), e.g.:

PID USER THR PRI NICE SIZE RES STATE TIME WCPU COMMAND
978 root 1 8 -20 5636K 2964K nanslp 18.2H 0.10% perl
8003 bind 1 4 20 28012K 1892K kqread 452:24 0.00% named
1019 root 1 4 -15 6172K 1332K sbwait 279:27 0.00% perl
...

Then you probably want to access the process table.

See:

http://search.cpan.org/~durist/Proc-ProcessTable-0.45/ProcessTable.pm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top