renice

processLinux/Unix
The renice command is one of the most frequently used commands in Linux/Unix-like operating systems. renice Alter priority of running processes

Quick Reference

Command Name:

renice

Category:

process

Platform:

Linux/Unix

Basic Usage:

renice [options] [arguments]

Common Use Cases

    Syntax

    renice priority [[-p] pid...] [[-g] pgrp...] [[-u] user...]

    Options

    Option Description
    -p, --pid Interpret arguments as process IDs (default)
    -g, --pgrp Interpret arguments as process group IDs
    -u, --user Interpret arguments as usernames
    -n, --priority Specify the nice increment value (some versions)
    -h, --help Display help message and exit
    -v, --version Output version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the renice command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    sudo renice +5 -p 1234
    Decrease priority of process with PID 1234 by 5.
    sudo renice -10 -p 5678
    Increase priority of process with PID 5678 (negative values give higher priority).
    # Advanced Examples Advanced
    sudo renice +10 -u username Decrease priority of all processes owned by username. sudo renice -5 -g 100 Increase priority of all processes in process group 100. sudo renice 15 -p 1234 5678 9012 Set nice value to 15 (lower priority) for multiple processes. sudo renice 0 -u root Reset the priority of all root-owned processes to the default. renice +1 $$ Slightly decrease the priority of the current shell. ps -l | grep firefox sudo renice +5 -p $(pgrep firefox) Find Firefox processes and decrease their priority. sudo renice +10 -u mysql -p 1234 Change priority for both a specific process and all processes of a user. nice -n 10 ./script.sh & sudo renice -5 $! Start a process with low priority, then increase its priority.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `renice` command is a system administration tool used to alter the scheduling priority ("niceness") of running processes in Unix-like operating systems. It provides a way to adjust how the CPU time is allocated among various processes, allowing system administrators to fine-tune system performance. In Unix/Linux systems, process scheduling priority is determined by a "nice" value, which typically ranges from -20 (highest priority) to +19 (lowest priority). The `renice` command allows changing this value for processes that are already running, while the related `nice` command is used to start a process with a specific priority level. Key aspects of the `renice` command include: 1. Priority Adjustment: The primary purpose is to adjust how much CPU time a process receives relative to other processes. 2. Permission Requirements: Ordinary users can only decrease the priority of their own processes (increase the nice value), while root can both increase and decrease process priorities. 3. Process Selection Flexibility: Can target specific processes (by PID), process groups, or all processes owned by a specific user. 4. Relative or Absolute Values: Can specify either a relative adjustment to the current nice value or an absolute nice value, depending on the syntax used. Common use cases for the `renice` command include: - Lowering the priority of CPU-intensive background tasks to prevent them from impacting interactive performance - Increasing the priority of critical services or applications - Balancing resource allocation between competing workloads - Troubleshooting performance issues by adjusting process priorities - Managing resource allocation in multi-user systems It's important to note that adjusting process priority affects only CPU scheduling and does not impact other resources like memory allocation or I/O priority. For more comprehensive resource control, modern Linux systems often use the more sophisticated cgroups (control groups) mechanism. The `renice` command is particularly useful in scenarios where system resources are constrained, and certain processes need to be prioritized over others. For example, on a server running both database and web services, an administrator might increase the priority of the database processes to ensure consistent performance under load. While `renice` is a powerful tool, it should be used judiciously. Setting extremely high priorities (very negative nice values) for certain processes can potentially starve other important processes of CPU time, leading to system instability or unresponsiveness.

    Related Commands

    These commands are frequently used alongside renice or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the renice command works in different scenarios.

    $ renice
    View All Commands