0

ps -o pcpu must show really obsolete CPU usage:

user@comp:~/acr/bin$ ps -o pid,pcpu,comm k-pcpu -u `whoami` | head

  PID %CPU COMMAND
 3709 34.7 R
15292 34.4 R
 3603 33.8 R
 3593 33.1 R
 3864 33.1 R
 3833 32.8 R
 3623 32.4 R
 3723 32.3 R
 3809 32.3 R

Current usage is zero. The top shows some small percentage but really these processes are just waiting for user input now:

user@comp:~/acr/bin$ top

top - 21:39:03 up 55 days,  6:01,  4 users,  load average: 0.89, 0.79, 0.81
Tasks: 648 total,   2 running, 646 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.2 us,  0.3 sy,  0.0 ni, 99.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.5 st
KiB Mem : 23920025+total, 19068168+free, 43706008 used,  4812568 buff/cache
KiB Swap:  8265724 total,  8232252 free,    33472 used. 19399897+avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 8431 user      20   0  778708 293092  13932 S   2.3  0.1  54:05.37 R
 8504 user      20   0  765680 279928  13904 S   2.3  0.1  47:20.29 R
 9217 user      20   0  766256 280460  13884 S   2.3  0.1  48:35.28 R
12921 user      20   0  763716 278040  13924 S   2.3  0.1  34:58.31 R
12998 user      20   0  765096 279276  13892 S   2.3  0.1 129:13.39 R
13026 user      20   0  764736 280960  13884 S   2.3  0.1 130:57.73 R
13093 user      20   0  765824 280056  13884 S   2.3  0.1  22:41.56 R
13208 user      20   0  765696 279884  13920 S   2.3  0.1  39:41.12 R
13325 user      20   0  776420 290744  13912 S   2.3  0.1  35:56.80 R
13832 user      20   0  765244 279424  13888 S   2.3  0.1 128:38.19 R

The ps showing more than 30% - that must be done over some ridiculously large time window of at least 24 hours, since these processes haven't been processing anything in the last 12 hours at least!! Before that, they were working 100%.

Questions:

  1. Where is the problem - is it some bug?
  2. How to make it show the current usage?

My system is CentOS Linux release 7.6.1810 (Core), on a 32 CPU Virtual Machine.

1

man ps says of %CPU:

Currently, it is the CPU time used divided by the time the process has been running (cputime/realtime ratio), expressed as a percentage.

So it is historical since the process started.

Top show the values in each -delay timeslice.

top has a -b (batch) option which outputs the report in text instead of using ncurses. You could pick out what you want from that, with due regard for the -d and -n options.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.