Explain the output please

Hello.
Could some nice soul please explain for me the output of the instruction:
system("top -n1 | grep \"Cpu(s)\"");
?

Thanks in advance

EDIT: The code outputs nothing, and so is system("free -m)");Why is it?
Last edited on
top command gives the system's present memory usage details. for options to top, you can consult 'man top'.

Edit:
(See the link given by naraku9333)

'-n1' does not seem to be a valid command option for top but I am not sure.

The output of this command is piped to grep that searches for the text "Cpu(s)" in this output.
Last edited on
It's a cheap way to get the total CPU use of the system at that instant. For eample, my system returned:
 
Cpu(s):  6.4%us,  1.0%sy,  0.0%ni, 91.9%id,  0.7%wa,  0.0%hi,  0.0%si,  0.0%st
@abhishekm71
The n option specifies the number of iterations top will take, without it top runs in the foreground. I wonder if that man page link you posted is specific to the unix version of top, the linux I have available have the n option as iterations. http://linux.die.net/man/1/top
@naraku9333
Thanks for the correction. I was lazy enough not to try out the option on my machine.
Topic archived. No new replies allowed.