Linux stress command With Examples
Last Updated :
08 Sep, 2024
The 'stress' command is a robust command-line tool available on Linux-based operating systems. It's designed to assess the performance and reliability of hardware and software by simulating a high-load environment. Here we will cover everything from installation to practical usage.
Introduction to "stress" command
'stress' is a command-line tool available in Linux to test the performance and reliability of computer systems. It has a variety of use cases like -
- System scalability testing by system administrators.
- Performance analysis by kernel programmers.
- Bug detection by systems programmers in high-load scenarios.
As per the description available for the command:
Note: This is a tool that imposes a configurable amount of CPU, memory, I/O, or disk stress on a POSIX-compliant operating system and reports any errors it detects.
In simplified terms, the command can stress the CPU, memory, I/O, or disk of the system (which is POSIX-compliant) and report any errors if detected during the stress process. Moreover, we can configure the level of stress. Also, remember that stress is not a benchmark tool (at least by intention).
Note: It is advised to run 'stress' with appropriate user privileges, such as 'sudo' or as the root user, to ensure it functions correctly.
Installation of `stress` command in Linux
stress can be installed using package managers available on different linux systems. Here are the commands for a few popular distros:
1. For Fedora/Red Hat:
$ sudo dnf install stress
2. For Debian/Ubuntu:
$ sudo apt-get install stress
Here is a screenshot from the installation on Fedora -
Figure 1: Terminal output on Fedora, the result of stress command installation.Once installed, you can reassure yourself using the command -
$ stress --version
If installed successfully, it outputs the version number (as shown in the screenshot below) -
Figure 2: Screenshot showing version number of stress on terminalUsage 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.
'stress' command Examples in Linux
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.
1. 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.
Figure 3: Screenshot showing the effect of stressing CPU with stress command.2. Stressing the memory with stress command
Syntax:
$ stress --vm N --vm-bytes B
where,
- N is the number of workers
- 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.
Figure 4: Screenshot showing the effect of stressing memory with the stress command.3. 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.
Conclusion
'stress' is a simple yet powerful open-source command line tool to test a system under stress (heavy load). It can be used to stress hard disk, io, memory, and CPU in any POSIX-compliant operating system (such as Linux) and it will report any errors encountered while stressing. Moreover, we can combine multiple stress tests together and/or configure the magnitude of each separately too.
Similar Reads
Linux make Command with Examples The make command for Linux is a very useful utility in the automation of software development and performing tasks in a Linux environment. It simply reads a special file, which is called a Makefile and this file describes how one's program is compiled and linked with another file or another program
6 min read
seq command in Linux with Examples The 'seq' command in Linux is a powerful utility used to generate a sequence of numbers. It is particularly useful in scenarios where you need to create a list of numbers within loops, such as while, for, or until loops. With 'seq', you can quickly generate numbers from a starting value (FIRST) to a
4 min read
type command in Linux with Examples The type command in Linux is a useful utility for identifying how the shell will interpret a given command. It provides information on whether a command is a shell built-in, external binary, function, or alias, helping users understand the source of the command and its behavior. The command is parti
3 min read
whereis command in Linux with Examples 'whereis' command is used to find the location of source/binary file of a command and manuals sections for a specified file in Linux system. If we compare 'whereis' command with 'find' command they will appear similar to each other as both can be used for the same purposes but 'whereis' command prod
4 min read
whatis Command in Linux with Examples whatis command in Linux is used to get a one-line manual page description. In Linux, each manual page has some sort of description within it. So, this command search for the manual pages names and show the manual page description of the specified filename or argument. Syntax of the `whatis` command
5 min read
username Command in Linux With Examples Linux as an operating system holds the capabilities of handling multiple users each with a username and a display name (Full Name). So it is important to keep a check on the users and their related information in order to maintain the integrity and security of the system. Whenever a user is added it
4 min read