This Bash script allows you to view and change the CPU priority (niceness) of processes on your system. You can check the top 10 processes sorted by CPU usage, and if needed, adjust the CPU priority for a specific process.
- This script is designed to work on a Unix-like system (e.g., Linux).
- You should have
sudo
privileges to change the CPU priority of processes, as changing priorities may require elevated permissions.
-
Make the script executable:
chmod +x process_priority_changer.sh
-
Run the script:
./process_priority_changer.sh
-
Follow the on-screen instructions:
- The script will display the top 10 processes sorted by CPU usage.
- You can enter the PID of the process for which you want to change the CPU priority.
- Provide the new CPU priority level, where a lower value indicates higher priority (e.g., 10 for low priority, -10 for high priority).
- After changing the CPU priority of a process, the script attempts to run the
renice
command withsudo
if needed. You may be prompted to enter your password for elevated privileges.
Here's a sample execution of the script:
- View the top processes sorted by CPU usage.
- Enter the PID of the process you want to change the priority for.
- Enter the new CPU priority level (e.g., 10 for low priority or -10 for high priority).