sleep (command)
{{Short description|Unix command}}
{{lowercase}}
{{Infobox software
| name = sleep
| logo =
| screenshot = Sleepunix.png
| screenshot size =
| caption = The {{code|sleep}} command
| developer = AT&T Bell Laboratories, Microsoft, Microware, Trane Francks
| released = {{Start date and age|1973|11}}
| latest release version =
| latest release date =
| programming language = C
| operating system = Unix, Unix-like, V, Plan 9, Inferno, OS-9, MSX-DOS, FreeDOS, Windows, KolibriOS, IBM i
| platform = Cross-platform
| genre = Command
| license = coreutils: GPLv3+
FreeDOS: GPLv2
Plan 9: MIT License
| website =
}}
In computing, sleep is a command in Unix, Unix-like and other operating systems that suspends program execution for a specified time.
Overview
The sleep instruction suspends the calling process for at least the specified number of seconds (the default), minutes, hours or days.
{{code|sleep}} for Unix-like systems is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX and the Single Unix Specification.{{man|cu|sleep|SUS}} It first appeared in Version 4 Unix.{{man|1|sleep|FreeBSD}}
The version of sleep
bundled in GNU coreutils was written by Jim Meyering and Paul Eggert.{{Cite web|url=https://linux.die.net/man/1/sleep|title=sleep(1): delay for specified amount of time - Linux man page|website=linux.die.net}} The command is also available in the OS-9 shell,{{cite book|author=Paul S. Dayan|year=1992|title=The OS-9 Guru - 1 : The Facts|publisher=Galactic Industrial Limited|isbn=0-9519228-0-7}} in the KolibriOS Shell,{{Cite web|url=http://wiki.kolibrios.org/wiki/Shell|title=Shell - KolibriOS wiki|website=wiki.kolibrios.org}} and part of the FreeDOS Package group Utilities.{{Cite web|url=http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/group-util.html|title=ibiblio.org FreeDOS Group -- Utilities|website=www.ibiblio.org}} The FreeDOS version was developed by Trane Francks and is licensed under the GPL.{{Cite web|url=http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/sleep.html|title=ibiblio.org FreeDOS Package -- sleep (Unix-like)|website=www.ibiblio.org}}
A sleep
command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.{{Cite web|url=https://archive.org/details/MSXDOS2TOOLS|title=MSX-DOS2 Tools User's Manual - MSX-DOS2 TOOLS ユーザーズマニュアル|date=April 1, 1993|via=Internet Archive}}
In PowerShell, sleep
is a predefined command alias for the Start-Sleep
cmdlet which serves the same purpose.{{Cite web|url=https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/start-sleep|title=Start-Sleep (Microsoft.PowerShell.Utility) - PowerShell|website=docs.microsoft.com}} Microsoft also provides a sleep
resource kit tool for Windows which can be used in batch files or the command prompt to pause the execution and wait for some time.{{Cite web |url=https://www.microsoft.com/en-us/download/details.aspx?id=17657 |title=Download Windows Server 2003 Resource Kit Tools from Official Microsoft Download Center |website=Microsoft |access-date=2018-08-10 |archive-date=2019-06-11 |archive-url=https://web.archive.org/web/20190611201442/http://www.microsoft.com/en-us/download/details.aspx?id=17657 |url-status=dead }} Another native version is the timeout
command which is part of current versions of Windows.{{Cite web|url=https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/cc754891(v=ws.11)|title=Timeout|website=docs.microsoft.com}}
The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}} The {{Mono|sleep}} command has also been ported to the IBM i operating system.{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=IBM |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 }}
Usage
sleep number
Where number is an integer{{cite web|url=https://linux.die.net/man/3/sleep|title=sleep(3): sleep for specified number of seconds - Linux man page|website=linux.die.net|access-date=19 April 2018}} number to indicate the time period in seconds. Some implementations support floating point numbers.
=Options=
None.
Examples
sleep 30
Causes the current terminal session to wait 30 seconds.
sleep 18000
Causes the current terminal session to wait 5 hours
=GNU sleep=
sleep 3h ; mplayer foo.mp3
Wait 3 hours then play the file {{mono|foo.mp3}}
Note that sleep 5h30m
and sleep 5h 30m
are illegal since sleep takes only one value and unit as argument. However, sleep 5.5h
(a floating point{{cite web|url=http://www.gnu.org/software/coreutils/sleep|title=GNU Coreutils: sleep invocation|website=www.gnu.org|access-date=19 April 2018}}) is allowed. Consecutive executions of sleep can also be used.
sleep 5h; sleep 30m
Sleep 5 hours, then sleep another 30 minutes.
The GNU Project's implementation of sleep (part of coreutils) allows the user to pass an arbitrary floating point or multiple arguments, therefore sleep 5h 30m
(a space separating hours and minutes is needed) will work on any system which uses GNU sleep, including Linux.
Possible uses for sleep
include scheduling tasks and delaying execution to allow a process to start, or waiting until a shared network connection most likely has few users to wget a large file.
See also
References
{{Reflist}}
External links
{{Wikibooks|Guide to Unix|Commands}}
- {{man|cu|sleep|SUS}}
- {{man|1|sleep|Plan 9}}
- {{man|1|sleep|Inferno}}
{{Unix commands}}
{{Plan 9 commands}}
{{Core Utilities commands}}
{{Windows commands}}
Category:Unix SUS2008 utilities
Category:Unix process- and task-management-related software
Category:Inferno (operating system) commands