Nginx 的 PID 是19910
其值为19在
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
其值为80在
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
其值为20在
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
我的问题如下:
- 为什么两个不同的命令的输出完全不同
ps
? - 和
PRI
之间有什么区别?ps
top
如果有人能向我解释,我将不胜感激。
答案1
根据这:
top
打印 的原始值priority
,即 的第 18 列/proc/[pid]/stat
,因此输出为20
ps -eo pri
打印 的值pri
,它等于39 - priority
,因此输出是39 -20 = 19
ps -l
,-l
选项打印 的值opri
,等于60 + priority
,因此输出为 '60 + 20 = 80'