2

top shows a priority of 20 for most processes, including (for example firefox-bin).

Whilst ps -o pid,lwp,pri,nice,start,stat,bsdtime,cmd,comm -C firefox-bin shows:

  PID   LWP PRI  NI  STARTED STAT   TIME CMD                         COMMAND
 9798  9798  19   0 14:03:47 Sl     2:17 /opt/firefox/firefox        firefox-bin

Since both top & ps are ancient commands, this seems unlikely to be a bug. Why the discrepancy?

Jeremy Boden
  • 1,320

2 Answers2

4

Linux priorities range from 0 to 139. You can see the true priority of a process by looking in the sched file in the process' /proc/ subdirectory. For example, Firefox on my system has a process ID of 84163. So, if I run grep ^prio /proc/84163/sched, it tells me the priority is 120. This is the default priority in Linux. Real-time priorities range from 0 to 99 and users can assign priorities from 100 to 139. However, ps tells me the priority of Firefox is 80 and top tells me it's 20. Why are all three different? According to this page, the priority given by ps ranges from -40 to 99. So, to get the real priority, add 40 to it. The top command subtracts 100 from each priority. So, to get the true priority in top, add 100 to it.

Rich
  • 41
2

Looks like top shows priority as 20 + nice value but ps shows 19 - nice value so both shows priority as value from 0 to 39 but in top 0 means highest priority but in ps 39 means highest priority.

I'm not sure why is this different and it is possible this is a bug in ps because its man page says "Higher number means lower priority."