getpriority - Linux


Overview

getpriority retrieves or sets the scheduling priority of a process or thread. This command is used to control the relative priority of a process in the Linux system scheduler.

Syntax

getpriority COMMAND
getpriority [-l|-n] [PID|COMMAND]
setpriority PRIORITY [-l|-n] [PID|COMMAND]

Options/Flags

-l: Lists all available priority levels.
-n: Displays numerical priority values instead of descriptions.
PRIORITY: A number between -20 to 19, where higher numbers indicate higher priority.
PID: Process ID of the target process.

Examples

  • Get the current priority of process with PID 1234:
getpriority -n 1234
  • Set the priority of process with PID 1234 to 10:
setpriority 10 -n 1234
  • List all available priority levels:
getpriority -l

Common Issues

  • If the user does not have sufficient permissions, the command will fail with an error.
  • Negative values for PRIORITY will cause an error.
  • Setting the priority too high may cause system instability.

Integration

Renice: getpriority can be used in combination with the renice utility to manage process priorities interactively.

  • Renice process with PID 1234 by 5 steps:
renice 5 -p 1234

Related Commands

  • ps: Display process information.
  • nice: Run a command with a modified priority.
  • top: Display system and process statistics.