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?

6
  • Does this answer your question? What is the difference between ps and top command?
    – taliezin
    Commented Oct 9, 2020 at 15:19
  • @taliezin, that suggested duplicate says nothing about the priority value displayed in each command. Commented Oct 9, 2020 at 15:23
  • The ps command displays a snapshot of typically just one process, whilst top is typically used to repeatedly display many processes and their effect on machine load. Commented Oct 9, 2020 at 15:29
  • 1
    @user4556274, I see, so this might be helpful.
    – taliezin
    Commented Oct 9, 2020 at 15:30
  • So its a reported issue? It seems a process can have many priorities... Commented Oct 9, 2020 at 15:42

2 Answers 2

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.

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."

2
  • If I use ps -o pri then this statement is also true, but as @user431397 points out, I am using the wrong kind of priority. Commented Oct 9, 2020 at 16:00
  • 1
    Interesting, ps manpage mentions only pri (and rprio for real time priority) not priority option/column. Commented Oct 9, 2020 at 16:07

You must log in to answer this question.

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