Re: Monitoring CPU usage of a process
There are easier ways than these, at least with this ps:
nujoma:~> ps --version
procps version 2.0.7
nujoma:~> ps -opid,cmd,%cpu -p 4400
PID CMD %CPU
4400 -csh 0.0
nujoma:~> ps -opid,cmd,%cpu -C ps
PID CMD %CPU
4436 ps -opid,cmd,%cp 0.0
put into a cron script or just dumped to a file, you'll have what you need
- no piping, grepping, etc., required.
If you're monitoring from within a perl script (which I often do), you can
do something like:
sub check_ps {
print LOG `/bin/ps -o%mem,%cpu -p$$`;
}
and then just throw in check_ps; statements wherever useful.
Hope this helps.
----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu
On Sun, 2 Jun 2002, Brian Dessent wrote:
> Adar Dembo wrote:
> >
> > I have some processes whose cpu usage I would like to monitor, and pipe
> > into a file. As far as I know, top can't monitor a single process and
> > send its cpu usage into a file, so I'm wondering what other programs
> > might do this. This is a testing installation, on a computer without any
> > GUI or anything sophisticated like that. Any help is greatly
> > appreciated.
>
> How about ps piped through grep and then sent to the file?
>
> ps -Al | grep foo >> bar
>
> If you just want cpu usage percent, try this:
>
> ps -Ao "comm pcpu" | grep foo >> bar
>
> Make it into a simple shell script with a loop and a delay if you want a
> periodic output. Add a call to date if you want timestamps.
>
> #!/bin/sh
> while sleep 10; do
> date +%H:%M:%S >> bar
> ps -Ao "comm pcpu" | grep foo >> bar
> done
>
> There's about a million ways to skin this cat.
>
> Brian
>
>
> --
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
>
--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Reply to: