Load all CPU cores on Linux with yes and gzip
Bash script that loads all CPU cores for one minute with yes and gzip, to test load on Linux.
This Bash script loads all CPU cores for 60 seconds by starting one yes | gzip pipeline per core. It can be used to test CPU load on a machine or to check how a monitoring tool reacts to it.
#!/bin/bash
# Définir le nombre de threads correspondant au nombre de cœurs du processeur
threads=$(nproc)
# Lancer des tâches yes gzip sur tous les threads
for ((i=0; i<threads; i++))
do
yes | gzip > /dev/null &
done
# Attendre une certaine durée de temps
sleep 60
# Terminer les tâches yes gzip
killall yes
How it works
nprocreturns the number of cores, and oneyes | gziptask is started for each of them.yeswrites in a loop, andgzipcompresses that stream to/dev/null.killall yesstops theyesprocesses. Thegzipprocesses then exit, because their input is closed.killallcomes from thepsmiscpackage on most distributions.