sleep doesn't work on Ubuntu 20.04 (WSL)
Solution 1
This is because of a bug in WSL1. Look here: https://discourse.ubuntu.com/t/ubuntu-20-04-and-wsl-1/15291
The upcoming Ubuntu 20.04 implements glibc 2.31. Unless you are on Insider you have not gotten the fix for issue 4989 yet and likely will not for a couple months. Without the fix things tend to break on Ubuntu 20.04 on WSL 1, sometimes even in the upgrade process 9 to Ubuntu 20.04. For example htop doesn’t work on Ubuntu 20.04 on unpatched WSL 1.
Solution 2
wget https://launchpad.net/~rafaeldtinoco/+archive/ubuntu/lp1871129/+files/libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb
sudo dpkg --install libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb
sudo apt-mark hold libc6
sudo apt --fix-broken install
sudo apt full-upgrade
How to upgrade Ubuntu 18.04 to 20.04 on WSL Windows 10
Solution 3
Just had this problem and I replaced the /usr/bin/sleep
binary with a python script that roughly replaces the functionality.
Backup /usr/bin/sleep
and replace with the file with the following contents
#!/usr/bin/env python3
import sys
import time
time.sleep(int(sys.argv[1]))
Remember to chmod +x /usr/bin/sleep
after replacing.
Solution 4
This command worked for me. use with root user privilege.
apt-mark hold libc6
apt --fix-broken install
apt full-upgrade
Solution 5
It's far from ideal but another workaround is to edit /var/lib/dpkg/info/libc6:amd64.postinst
and comment out the set -e
at the top of the script (insert a #
as the first character in the line).
You will still receive the sleep: cannot read realtime clock: Invalid argument
error but it will not cause the upgrade of the package to abort.
It's not ideal because:
- A standard post-install script is modified.
- The script change must be applied every time
libc6
is upgraded.
Related videos on Youtube
Dmitriy Lyutov
Updated on September 18, 2022Comments
-
Dmitriy Lyutov over 1 year
After upgrading to 20.04 on WSL sleep doesn't work with an error:
sleep: cannot read realtime clock: Invalid argument
-
Kulfy about 4 yearsIt seems that many of your answers consists the link how2shout.com. If you're the owner of that domain, please disclose your affiliation. See How to not be a spammer.
-
C. Gonzalez almost 4 years... Doesn't that just replace
/bin/sleep
with an empty file? This is a terrible hack and is bound to break things in unexpected ways. -
Asfand Qazi almost 4 yearsYeah, it may get you past some sticky situations, but sleep is a standard UNIX command and no doubt just replacing it with an empty file that does nothing is going to screw up a lot of things.
-
Flimm almost 4 yearsIsn't a good idea to run
sudo apt-mark unhold libc6
at the end? -
Ryan over 3 yearsThose 3 commands didn't work for me until I prepended
sudo
to each, and only after runningsudo apt-get update
. Then they seemed to solve this problem. So I guess I'll +1. -
Ryan over 3 yearsI'd prefer if this answer explained what that random
.deb
package is and what the risks are of installing it and whether (and how) it would be easy to revert back later. -
Ryan over 3 yearsThis looked interesting, but I got an error:
sudo service supervisor start Starting supervisor: /bin/sleep: 1: read: Illegal option -n
-
Ryan over 3 years
sudo cp -p /usr/bin/sleep /usr/bin/sleep.orig
andsudo vim /usr/bin/sleep
were helpful commands for me. I think your hack might be working for me, although in my Windows Task Manager, I see a php7.4 background process with "Very high" for "Power usage", and I don't know why. -
Ryan over 3 yearsActually, I don't think it worked for me, but I can't remove my upvote. Currently I'm hoping askubuntu.com/questions/1230252/… works.
-
domenukk over 3 yearsI needed to replace
/bin/sleep
instead, on my ubuntu installation. -
Lh Lee over 3 yearsgithub.com/u-root/u-root/blob/master/cmds/core/sleep/sleep.go I used this instead as I needed support for seconds/minutes etc.