Linux stress Command – Stress Test CPU

A performance test will put load on your Linux machine and stress test components like the CPU, memory, and hard drive. The stress Linux command is an ideal utility to put load on a computer and push your hardware to its limits. In this tutorial, you will learn how to install and use the stress and stress-ng commands and their various options.

Install stress / stress-ng Command

Install the stress command using the appropriate command below.

$ sudo apt install stress # Ubuntu, Debian
$ sudo dnf install stress # Fedora, CentOS, AlmaLinux
$ sudo pacman -S stress # Arch Linux, Manjaro

Depending on the tests you’d like to run, you may opt for the stress-ng command instead. You’ll see some of the differences below.

$ sudo apt install stress-ng # Ubuntu, Debian
$ sudo dnf install stress-ng # Fedora, CentOS, AlmaLinux
$ sudo yay -S stress-ng # Arch Linux, Manjaro (install from AUR)

Stress Test CPU

Example 1. You can put load on the CPU by using the -c option.

$ stress -c 1 # 1 process
$ stress -c 5 # 5 processes

Use Ctrl + C to stop the process at any time.

As the stress command does its job, you may want to use commands like top or htop in another terminal to monitor the current CPU usage.

Example 2. You can also specify how long you want the load to persist.

$ stress -c 1 -t 10s # 10 seconds
$ stress -c 1 -t 5m # 5 minutes
$ stress -c 1 -t 1h # 1 hour

Example 3. Use the stress-ng command and the -l option to specify what percentage of the CPU you want to put load on.

$ stress-ng -c 1 -l 25 # 25% load
$ stress-ng -c 1 -l 50 # 50% load

Stress Test Memory

With the --vm flag, you can put pressure on the memory. You can also set the memory size to test by using the --vm-bytes option.

$ stress --vm <the number of the process> --vm-bytes <memory size> -t <time>

Stress Test Hard Drive / SSD

Example 1. With the -d option, you can put load on the disk by writing and deleting repeatedly. The default size is 1GB.

$ stress -d <the number of the process> -t <timeout>

Example 2. If you want to change the default size of the file that’s being written, you can use the --hdd-bytes flag in conjunction with the -d option.

$ stress -d <the number of the process> --hdd-bytes <file size> -t <timeout> 

Leave a Comment

Your email address will not be published. Required fields are marked *