1

nginx PID is 19910

  1. The value is 19 in ps -eo pri

     ps -eo pid,ppid,ni,pri,psr,pcpu,stat,cmd |head -n1;ps -eo pid,ppid,ni,pri,psr,pcpu,stat,cmd |grep nginx PID PPID NI PRI PSR %CPU STAT CMD 19910 1 0 19 0 0.0 Ss nginx: master process /usr/sbin/nginx 19911 19910 0 19 2 0.0 S nginx: worker process 19912 19910 0 19 1 0.0 S nginx: worker process 19914 19910 0 19 1 0.0 S nginx: worker process 19915 19910 0 19 0 0.0 S nginx: worker process 
  2. The value is 80 in ps -elf

     ps -elf |head -n1;ps -elf |grep nginx F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 5 S root 19910 1 0 80 0 - 21487 sigsus Jul29 ? 00:00:00 nginx: master process /usr/sbin/nginx 5 S www-data 19911 19910 0 80 0 - 21576 ep_pol Jul29 ? 00:01:55 nginx: worker process 5 S www-data 19912 19910 0 80 0 - 21576 ep_pol Jul29 ? 00:02:05 nginx: worker process 5 S www-data 19914 19910 0 80 0 - 21576 ep_pol Jul29 ? 00:02:00 nginx: worker process 5 S www-data 19915 19910 0 80 0 - 21576 ep_pol Jul29 ? 00:02:08 nginx: worker process 
  3. The value is 20 in top -b -n 1 -p

     top -b -n 1 -p 19910 top - 09:57:13 up 435 days, 19 min, 2 users, load average: 0.00, 0.00, 0.00 Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.1 us, 0.1 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 8175360 total, 4617480 used, 3557880 free, 167444 buffers KiB Swap: 8384508 total, 10408 used, 8374100 free. 3955108 cached Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 19910 root 20 0 85948 2944 1784 S 0.0 0.0 0:00.00 nginx 

My question is as follows:

  1. Why the output is totally different in two different ps command?
  2. What's the difference of PRI between ps and top?

I'll appreciate if anyone can explain it to me.

1 Answer 1

2

Accoring to this:

top print the raw value of priority, which is column 18 of /proc/[pid]/stat,thus the output is 20

ps -eo pri print the the value of pri, which is equal to 39 - priority,thus the output is 39 -20 = 19

ps -l, -l option print the value of opri,which is equal to 60 + priority,thus the output is '60 + 20 = 80'

1
  • There is no answer in the past few days, and I find out the reason, so I post the answer myself. Commented Sep 5, 2021 at 18:19

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.