getting value from TOP command

Hello, everybody,
I’m interesting how can I get a single value from TOP command (I mean, a single value that represents a CPU usage by a certain process). This problem comes from following:
I use “top” to evaluate an average of CPU usage by a certain process. If you would put duration to 0.2 (refresh time for “top”), every 0.2 seconds you’ll get a new value. It is hard to evaluate the average using the “top” table. That’s why I want to get every 0.2 seconds just a value, put it into a stack. After, say, a minute, take all values and evaluate the average. Is it possible to do?
Thanks in advance.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Why not use ‘ps’?

ps aux | grep processName | grep -v grep | awk ‘{print $3}’

Replace ‘processName’ with your process.

Good luck.

diktofon wrote:
> Hello, everybody,
> I’m interesting how can I get a single value from TOP command (I mean,
> a single value that represents a CPU usage by a certain process). This
> problem comes from following:
> I use “top” to evaluate an average of CPU usage by a certain process.
> If you would put duration to 0.2 (refresh time for “top”), every 0.2
> seconds you’ll get a new value. It is hard to evaluate the average using
> the “top” table. That’s why I want to get every 0.2 seconds just a
> value, put it into a stack. After, say, a minute, take all values and
> evaluate the average. Is it possible to do?
> Thanks in advance.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJEed93s42bA80+9kRAsDuAJ9G0oqVPDkFVGjH+JIdedkH++j+ygCfSc3S
gOzrdLxdOXpfwtTv12cXheA=
=a738
-----END PGP SIGNATURE-----

That is cool! Thanks. Does anybody have an idea, how to put it now into the script, that will execute that command automatically each 0.2 seconds and put the obtained values into text file? (I do not ask for the script, just ideas).

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

#!/bin/bash
while 1 ]; do
ps aux | grep processName | grep -v grep | awk ‘{print $3}’ > filename
sleep 0.2
done

There’s a start.

Good luck.

diktofon wrote:
> ab@novell.com;1892160 Wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Why not use ‘ps’?
>>
>> ps aux | grep processName | grep -v grep | awk ‘{print $3}’
>>
>> Replace ‘processName’ with your process.
>>
>>
>
> That is cool! Thanks. Does anybody have an idea, how to put it now into
> the script, that will execute that command automatically each 0.2
> seconds and put the obtained values into text file? (I do not ask for
> the script, just ideas).
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJEitZ3s42bA80+9kRAhHXAJ9E/7iMmBKv7qs1DmEFgVwzbJFo0QCfah26
SWnI61ucGkPuko5EOpkrpt0=
=HQCR
-----END PGP SIGNATURE-----

top has a -b option which prints to stdout. It’s intended to let you filter the output in whatever way you want. See the man page.

Not meaning to hijack the thread… but thinking along these lines when looking at CPU values in top, it does not always correspond with what processes are doing.

For instance… the processes can be running normally (no heavy CPU use), but looking at the CPU’s itself the wa (wait for access?) can be as high as 99%.

How does one go about finding out what is causing that if it does not seem directly related to a running process?

Wait is wait for I/O completion, so it would be due to device I/O holding things up.

Sorry for my stupidness, but when I try to write all this lines in Konsole, I’ve got the message:

alexey@right:~> while [1]; do
> ps aux|grep Xorg|grep -v grep|awk ‘{print $3}’ > my.txt
> sleep 0.2
> done
bash: [1]: command not found

Am I doing something wrong? Maybe I have to use another program instead of Shell?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Put spaces around ‘1’ on the while line.

Good luck.

diktofon wrote:
> ab@novell.com;1892300 Wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> #!/bin/bash
>> while 1 ]; do
>> ps aux | grep processName | grep -v grep | awk ‘{print $3}’ > filename
>> sleep 0.2
>> done
>>
>> There’s a start.
>>
>> Good luck.
>>
>>
>
> Sorry for my stupidness, but when I try to write all this lines in
> Konsole, I’ve got the message:
>
> alexey@right:~> while [1]; do
>> ps aux|grep Xorg|grep -v grep|awk ‘{print $3}’ > my.txt
>> sleep 0.2
>> done
> bash: [1]: command not found
>
> Am I doing something wrong? Maybe I have to use another program instead
> of Shell?
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJGHFe3s42bA80+9kRAq9tAJ0bNaemifgKx0bOhaFcRE575zy/EgCfdHnM
1SJBQb6kp8b2dB0+D0KsxoM=
=+7Vk
-----END PGP SIGNATURE-----