AMZ DIGICOM

Digital Communication

AMZ DIGICOM

Digital Communication

sleep command: pause processes

PARTAGEZ

With Linux sleep, you can pause processes and resume their execution later. The command works under Linux, even in combination with other commands, and can be adapted using various parameters.

What is Linux sleep?

The Linux sleep command is used to pause a process for a predefined period. Indeed, the user decides the duration of the pause and the resumption or stopping of the process after this pause. The sleep command is not only part of all standard Linux distributions, such as Debian or Ubuntu, so there is no need to install it additionally, but it also has a correspondence in other operating systems. The sleep command is a simple and very useful tool, especially when shell scripts need to be forcefully paused.

How does the sleep command work?

How the sleep command works is explained very quickly. You indicate next to the order itself a duration and, if applicable, a time unit parameter. Although the latter is presented by default in seconds, it can also be set in minutes, hours or even days. The time value can be specified as an integer, but also as a floating point number. However, a period replaces the decimal point of this type of number. Multiple sleep commands can be executed one after the other. If you want to execute a sequence of commands, use an AND (“&&”) operation. We present an example of this type of command below.

What is the syntax of the sleep command?

The syntax for Linux sleep is as follows:

$ sleep [Nombre] [Suffixe]

bash

The sleep command is always used on the current process unless you specify another program.

What are the Linux sleep options and settings?

The sleep command has only two options: “-h” or “–help” to get information about the sleep command and “-v” or “–version” to get information about the version, license and development. However, you can define the time unit yourself. The allowed parameters are:

  • s : the period is indicated in seconds. This is the default setting. If you do not specify a suffix, the numerical value is calculated in seconds.
  • m : the period is indicated in minutes.
  • h : the period is indicated in hours.
  • d : the period is indicated in days.

Examples of using the sleep command

Finally, we present some examples of using Linux sleep.

Here, the current process will be paused for one minute (60 seconds) and then resume.

This command pauses the current process for two and a half hours.

$ sleep 2m && killall libreoffice

bash

By combining this command with the killall command, you stop the LibreOffice program two minutes after executing the sleep command.

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact