Introduction

Sometimes, you may want to limit the CPU usage of a specific process on your Linux VPS to prevent resource hogging or maintain server performance. CPULimit is a tool that allows you to limit the CPU usage of processes. This guide will show you how to use CPULimit on Linux VPSto restrict CPU usage effectively.

Step 1: Install CPULimit on Windows

CPULimit is a Linux utility, and it is not natively available on Windows. However, you can use Linux VPSSubsystem for Linux (WSL) to run CPULimit on your Linux VPS.

Follow these steps to install WSL and CPULimit:

    1. Open PowerShell as Administrator and run the following command to install WSL:
wsl --install
    1. Restart your system when prompted to complete the WSL installation.
    2. Next, install a Linux distribution like Ubuntu from the Microsoft Store.
    3. After installation, open the Linux terminal and set up your user account.
    4. Now, update your package list by running:
sudo apt update

Step 2: Install CPULimit on Ubuntu via WSL

Now that you have WSL and Ubuntu installed, you can install CPULimit:

    1. In the Linux terminal, run the following command to install CPULimit:
sudo apt install cpulimit
    1. Confirm the installation by typing ‘Y’ when prompted.
    2. After installation, you can verify the CPULimit version by running:
cpulimit --version

Step 3: Limit CPU Usage with CPULimit

Now that CPULimit is installed, you can start limiting the CPU usage of any process. Here’s how to do it:

    1. Identify the process ID (PID) of the program you want to limit. You can do this by running:
ps aux
    1. Find the PID of the process you want to limit.
    2. Use the CPULimit command to restrict CPU usage. For example, to limit a process with PID 1234 to 50% CPU usage, run:
sudo cpulimit --pid 1234 --limit 50
  1. This command will limit the process to 50% CPU usage. You can replace ‘1234’ with the PID of the process you wish to limit and adjust the percentage as needed.

Step 4: Run CPULimit in the Background

If you want CPULimit to run in the background and keep the process limited even after you close the terminal, you can use the following command:

sudo cpulimit --pid 1234 --limit 50 --background

This will limit the process in the background without requiring the terminal to remain open.

Step 5: Limit CPU Usage for New Processes

If you want to limit CPU usage for a process before it starts, use the following command:

sudo cpulimit --exe /path/to/executable --limit 50

Replace /path/to/executable with the actual path of the program you want to run and limit the CPU usage to 50%.

Step 6: Troubleshooting

If CPULimit does not seem to work properly, try these troubleshooting tips:

  • CPULimit not installed: Ensure that you’ve installed CPULimit correctly by running cpulimit --version in the terminal.
  • Process not found: Double-check the PID or executable path and ensure the process is running.
  • Permission errors: Ensure that you have the necessary permissions to run CPULimit with sudo.

If the problem persists, refer to the official CPULimit documentation for more help.

Conclusion

You’ve successfully installed and used CPULimit to limit CPU usage on your Linux VPS. By using CPULimit, you can control the resource usage of your processes and ensure better performance and stability for your server.

© 2024. For more Linux VPS solutions, visit NetCloud24.