0

The top command gives information on running processes. The %CPU column gives the percentage of CPU each process is using (CPU usage).

Is there a simple way to print values of %CPU over wall clock time for a particular process (PID)?

3
  • 1
    What do you mean by "over time"? Over which time?
    – aviro
    Jan 25, 2022 at 17:17
  • @aviro Good point! I mean over wall clock time. At 03:31:01, %CPU for the process was X%; at 03:31:02, %CPU for the process was Y%. I want to find X and Y.
    – Andrew
    Jan 25, 2022 at 17:29
  • 1
    You want to see those in real time, or you want to be able to see past values after the process already started? Meaning, do you just want to see how much CPU the procees consumed in total at the moment you check?
    – aviro
    Jan 25, 2022 at 17:40

1 Answer 1

1

Do you really want a 1 second granularity on the output? You can try the following:

PID=7101
while [[ -d /proc/$PID ]]
do
    ps u k-pcpu --noheaders -p $PID | awk '{print $3}'
    sleep 1
done

Timestamps can be added at will.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .