Usage of `stress` command in Linux
The syntax to use the command is as follows-
$ stress [options]
Here is a list of basic options –
Options |
Short forms |
Description |
---|---|---|
–hdd |
-d |
stress the storage. |
–CPU |
-c |
stress the CPU. |
–vm |
-v |
stress the memory. |
–io |
-i |
stress io. |
–timeout |
-t |
decide the time period for the stress (in seconds). |
A list of all the available options and their precise usage description can be obtained by running the command –
$ man stress
It will open the man (manual) page for the command.
Now we see a few usage examples. The screenshots are from “Fedora” but the working is the same across all distributions. The approach in the screenshots is simple – I have opened the terminal on left half and the system-monitor application on the right half. We run the commands on the terminal and monitor the load on the system monitor.
Stressing the CPU with a stress command
Syntax :
$ stress -c N
N is an integer specifying the number of CPUs to stress. For example, here is the command to stress 8 CPU cores with a timeout of 10 seconds-
$ stress -c 8 --timeout 10
Below (Figure 3) is the resultant screenshot. One can notice in the top graph of the system monitor (right) that the CPU usage shoots up to 100% while the command is running.
Stressing the memory with stress command
Syntax :
$ stress --vm N --vm-bytes B
where N is the number of workers and B is the malloc bytes per worker (256M by default).
For example here is the command to stress the memory with 20 workers each of size 128M for 10 seconds-
$ stress --vm 20 --vm-bytes 128M --timeout 10
Figure 4 shows the resultant screenshot. Notice the middle graph (titled Memory and Swap) grew suddenly depending on the amount of stress we specified. Also, the CPU usage has spiked to full load.
Combining different loads
We can even combine different loads. For example, with this command, we combine CPU and memory load –
$ stress -c 8 --vm 20 --vm-bytes 128M --timeout 5
This says stress 8 CPU cores and memory with 20 service workers each with malloc size 128M for 5 seconds.
Linux stress command With Examples
This article introduces stress command, a command line tool available for Linux-based operating systems to evaluate the performance and reliability of a system under a variety of workloads by introducing stress (heavy load) to the system. First, we see the introduction, then the installation, and finally usage.
Contact Us