CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Process Management / renice

renice

Change the priority of a running process

Intermediateschedulingperformanceprocesses

renice changes the nice value of processes that are already running, by PID, process group or user. It's how you calm down a runaway job without killing it. Normal users can only increase niceness (lower priority); going back down needs root.

Syntaxrenice [-n] PRIORITY [-p] PID... | -g PGRP... | -u USER...

Watch it run

A report worker is eating a full core and the API is slowing down. Lower its priority instead of killing it.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
renice -n 10 -p 2290

Your own process, and you are making it nicer, so no sudo needed. renice prints the old and new values. 'priority' here means the nice value.

Anatomy of a command

$
commandsudo

Needed to renice other users' processes or to lower a nice value.

How it works

renice is a loop around the setpriority(which, who, prio) system call, with which set to PRIO_PROCESS (-p), PRIO_PGRP (-g) or PRIO_USER (-u). It first calls getpriority() to print the old value, then sets the new one and reports both. The kernel checks permissions: you must own the target, and lowering the nice value below its current value needs CAP_SYS_NICE or a high enough RLIMIT_NICE. On Linux, nice is per thread, and PRIO_PROCESS with a PID changes only the thread whose ID equals that PID (the main thread). PRIO_PGRP and PRIO_USER walk every thread of every matching process. So for a multi-threaded server, renice -g PGID or renicing each TID in /proc/PID/task is what actually lowers the whole process. New threads inherit the value of the thread that creates them.

Options you'll actually use

-n NThe new nice value (-20..19)
-p PIDTarget processes by ID (the default target type)
-g PGRPTarget every process (and thread) in a process group
-u USERTarget every process owned by a user
--relativeTreat -n as an increment instead of an absolute value
+N / NOld syntax: renice +5 -p PID sets nice to 5

Common mistakes

renice -n 10 -p PID on a Java or Node server and assuming it's done

Nice is per thread on Linux; -p changes only the main thread, while worker threads keep the old value.

renice -n 10 -g PGID, or renice each ID in /proc/PID/task
Raising niceness during an incident, then trying to undo it as a normal user

Lowering niceness needs root, even for your own processes.

Use sudo renice, or restart the process
Renicing a user's processes to fix things long-term

renice only affects processes running now; new ones start at the default again.

Nice= in the systemd unit, or limits.conf priority for the user

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Start `sleep 900 &` and change its niceness to 12. Confirm with ps.

  2. 2

    Try to set that sleep back to niceness 0 without sudo. What happens? Now do it with sudo.

  3. 3

    Raise the niceness of all your own processes to 5 in one command.

Related commands

niceStart a command with a lower (or higher) CPU prioritytopWatch CPU, memory and processes livepsSnapshot the running processeshtopInteractive process viewer with bars and a tree
PreviousniceNextnohup
Linux / Process Management / renice

renice

Change the priority of a running process

Intermediateschedulingperformanceprocesses

renice changes the nice value of processes that are already running, by PID, process group or user. It's how you calm down a runaway job without killing it. Normal users can only increase niceness (lower priority); going back down needs root.

Syntaxrenice [-n] PRIORITY [-p] PID... | -g PGRP... | -u USER...

Watch it run

A report worker is eating a full core and the API is slowing down. Lower its priority instead of killing it.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
renice -n 10 -p 2290

Your own process, and you are making it nicer, so no sudo needed. renice prints the old and new values. 'priority' here means the nice value.

Anatomy of a command

$
commandsudo

Needed to renice other users' processes or to lower a nice value.

How it works

renice is a loop around the setpriority(which, who, prio) system call, with which set to PRIO_PROCESS (-p), PRIO_PGRP (-g) or PRIO_USER (-u). It first calls getpriority() to print the old value, then sets the new one and reports both. The kernel checks permissions: you must own the target, and lowering the nice value below its current value needs CAP_SYS_NICE or a high enough RLIMIT_NICE. On Linux, nice is per thread, and PRIO_PROCESS with a PID changes only the thread whose ID equals that PID (the main thread). PRIO_PGRP and PRIO_USER walk every thread of every matching process. So for a multi-threaded server, renice -g PGID or renicing each TID in /proc/PID/task is what actually lowers the whole process. New threads inherit the value of the thread that creates them.

Options you'll actually use

-n NThe new nice value (-20..19)
-p PIDTarget processes by ID (the default target type)
-g PGRPTarget every process (and thread) in a process group
-u USERTarget every process owned by a user
--relativeTreat -n as an increment instead of an absolute value
+N / NOld syntax: renice +5 -p PID sets nice to 5

Common mistakes

renice -n 10 -p PID on a Java or Node server and assuming it's done

Nice is per thread on Linux; -p changes only the main thread, while worker threads keep the old value.

renice -n 10 -g PGID, or renice each ID in /proc/PID/task
Raising niceness during an incident, then trying to undo it as a normal user

Lowering niceness needs root, even for your own processes.

Use sudo renice, or restart the process
Renicing a user's processes to fix things long-term

renice only affects processes running now; new ones start at the default again.

Nice= in the systemd unit, or limits.conf priority for the user

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Start `sleep 900 &` and change its niceness to 12. Confirm with ps.

  2. 2

    Try to set that sleep back to niceness 0 without sudo. What happens? Now do it with sudo.

  3. 3

    Raise the niceness of all your own processes to 5 in one command.

Related commands

niceStart a command with a lower (or higher) CPU prioritytopWatch CPU, memory and processes livepsSnapshot the running processeshtopInteractive process viewer with bars and a tree
PreviousniceNextnohup