23

How can i view the priority of a specific process ?

6 Answers 6

24

awk '{print $18}' /proc/1337/stat (gets the prio for process 1337).

If the command of the process has spaces in it, something like awk '{print $(NF-34)}' /proc/1337/stat to calculate the field position backwards from the number of fields could be used.

Other options:

Use ps -o pri. Specify the process id with -p 1337. Or, use -e to list all processes.

Experiment with this as a starting point if you want more than just the priority:

ps -e -o uid,pid,ppid,pri,ni,cmd
2
  • 1
    Note: awk '{print $18}' may return wrong result if comm (2nd field in stat file) contains a space. Feb 23, 2021 at 17:33
  • Thanks for pointing that out @IrfanLatif. I updated the answer with one possible solution.
    – MattBianco
    Jan 18 at 14:02
11

The top command lists the priority of running processes under the PR heading. If you have it installed, you can also search for a process and sort by priority in htop.

5

ps is probably the right way to go. You can then grep and awk your way to the relevant row and column

5
ps -o ni $(pidof processname)

For example:

ps -o ni $(pidof mysqld)

# ps -o ni $(pidof mysqld) 
  NI
  15
3

If you have a cut-down Linux distribution where ps and top does not give you priority information, you can parse the stat file of proc for your process ID to get the priority information.

cat /proc/PID/stat | awk '{print "priority " $18 " nice " $19}'

The values at position 18 and 19 of stat file represent priority and nice

For more: https://linux.die.net/man/5/proc

0

You might exclude headers with --no-headers if ps have it. You could use "ps --no-headers -o pri $(pidof )" to just show priority. Use pgrep if you have no pidof.

You must log in to answer this question.

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