0

I'm developing a small utility in Java, that monitors a remote Linux machine's cpu. I'm using using sar command to monitor it. The problem is, when i write sar 1 1 it takes some time to get cpu usage. I tried sar 0 but it's showing same cpu values instead of online cpu usage. What can i do to take cpu usage instantly?

AloneInTheDark
  • 938
  • 4
  • 15
  • 36

1 Answers1

1

One option would be:

top

or

top | grep <App_name>

or

 ps -p <app_pid> -o %cpu

Edit

To obtain only the number of % use of cpu of a certain pid:

ps -p PID -o %cpu | sed 's/[^0-9]//g' | tr -d '\n'

or

ps -p PID -o %cpu | sed -n 2p | sed 's/ //'
Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146