Repository navigation
Description
- Your Windows build number:
Microsoft Windows [Version 10.0.15063]
- What you're doing and what's happening:
I am callingclock_nanosleepwith clockidCLOCK_REALTIME, and the call fails with errorEINVAL.
A self-contained example can be found in https://gist.github.com/traversaro/c2b6941ef2ddd10e9dd6c1800483696a .
On my system, the corresponding output is:
traversaro@system:~/src/clockid_wsl_test/build$ ./clockid_wsl_test
Error macros values:
EINTR : 4
EINVAL: 22
ENOTSUP: 95
Testing CLOCK_MONOTONIC
clock_getres return value: 0 with errno 0
clock_gettime return value: 0
clock_nanosleep return value: 0
Testing CLOCK_REALTIME
clock_getres return value: 0 with errno 0
clock_gettime return value: 0
clock_nanosleep return value: 22
Testing CLOCK_PROCESS_CPUTIME_ID
clock_getres return value: -1 with errno 22
clock_gettime return value: 0
clock_nanosleep return value: 22
Testing CLOCK_THREAD_CPUTIME_ID
clock_getres return value: -1 with errno 22
clock_gettime return value: 0
clock_nanosleep return value: 22
-
What's wrong / what should be happening instead:
The call should be successful, and sleep (at least) for the specified amount of time. -
Strace of the failing command, if applicable:
execve("./clockid_wsl_test", ["./clockid_wsl_test"], [/* 18 vars */]) = 0
brk(NULL) = 0x680000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc541a30000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=54863, ...}) = 0
mmap(NULL, 54863, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc541a22000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \235\10\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=1566440, ...}) = 0
mmap(NULL, 3675136, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc541270000
mprotect(0x7fc5413e2000, 2097152, PROT_NONE) = 0
mmap(0x7fc5415e2000, 49152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x172000) = 0x7fc5415e2000
mmap(0x7fc5415ee000, 13312, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc5415ee000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc540ea0000
mprotect(0x7fc541060000, 2097152, PROT_NONE) = 0
mmap(0x7fc541260000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7fc541260000
mmap(0x7fc541266000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc541266000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0V\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=1088952, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc541a20000
mmap(NULL, 3178744, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc540b90000
mprotect(0x7fc540c98000, 2093056, PROT_NONE) = 0
mmap(0x7fc540e97000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x107000) = 0x7fc540e97000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p*\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=89696, ...}) = 0
mmap(NULL, 2185488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc540970000
mprotect(0x7fc540986000, 2093056, PROT_NONE) = 0
mmap(0x7fc540b85000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7fc540b85000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc541a10000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc541a00000
arch_prctl(ARCH_SET_FS, 0x7fc541a00740) = 0
mprotect(0x7fc541260000, 16384, PROT_READ) = 0
mprotect(0x7fc540e97000, 4096, PROT_READ) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc5419f0000
mprotect(0x7fc5415e2000, 40960, PROT_READ) = 0
mprotect(0x601000, 4096, PROT_READ) = 0
mprotect(0x7fc541825000, 4096, PROT_READ) = 0
munmap(0x7fc541a22000, 54863) = 0
brk(NULL) = 0x680000
brk(0x6b2000) = 0x6b2000
write(2, "Error macros values: ", 21) = 21
write(2, "\n", 1) = 1
write(2, "EINTR : ", 8) = 8
write(2, "4", 1) = 1
write(2, "\n", 1) = 1
write(2, "EINVAL: ", 8) = 8
write(2, "22", 2) = 2
write(2, "\n", 1) = 1
write(2, "ENOTSUP: ", 9) = 9
write(2, "95", 2) = 2
write(2, "\n", 1) = 1
write(2, "Testing CLOCK_MONOTONIC ", 24) = 24
write(2, "\n", 1) = 1
clock_getres(CLOCK_MONOTONIC, {0, 400}) = 0
write(2, "clock_getres return value: ", 27) = 27
write(2, "0", 1) = 1
write(2, " with errno ", 12) = 12
write(2, "0", 1) = 1
write(2, "\n", 1) = 1
clock_gettime(CLOCK_MONOTONIC, {64792, 473106000}) = 0
write(2, "clock_gettime return value: ", 28) = 28
write(2, "0", 1) = 1
write(2, "\n", 1) = 1
clock_nanosleep(CLOCK_MONOTONIC, 0, {0, 100000000}, 0x7fffe836d990) = 0
write(2, "clock_nanosleep return value: ", 30) = 30
write(2, "0", 1) = 1
write(2, "\n", 1) = 1
write(2, "Testing CLOCK_REALTIME ", 23) = 23
write(2, "\n", 1) = 1
clock_getres(CLOCK_REALTIME, {0, 400}) = 0
write(2, "clock_getres return value: ", 27) = 27
write(2, "0", 1) = 1
write(2, " with errno ", 12) = 12
write(2, "0", 1) = 1
write(2, "\n", 1) = 1
clock_gettime(CLOCK_REALTIME, {1505639919, 799894800}) = 0
write(2, "clock_gettime return value: ", 28) = 28
write(2, "0", 1) = 1
write(2, "\n", 1) = 1
clock_nanosleep(CLOCK_REALTIME, 0, {0, 100000000}, 0x7fffe836d990) = -1 EINVAL (Invalid argument)
write(2, "clock_nanosleep return value: ", 30) = 30
write(2, "22", 2) = 2
write(2, "\n", 1) = 1
write(2, "Testing CLOCK_PROCESS_CPUTIME_ID"..., 33) = 33
write(2, "\n", 1) = 1
clock_getres(CLOCK_PROCESS_CPUTIME_ID, 0x7fffe836d960) = -1 EINVAL (Invalid argument)
write(2, "clock_getres return value: ", 27) = 27
write(2, "-1", 2) = 2
write(2, " with errno ", 12) = 12
write(2, "22", 2) = 2
write(2, "\n", 1) = 1
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {0, 15625000}) = 0
write(2, "clock_gettime return value: ", 28) = 28
write(2, "0", 1) = 1
write(2, "\n", 1) = 1
clock_nanosleep(0xfffffffa /* CLOCK_??? */, 0, {0, 100000000}, 0x7fffe836d990) = -1 EINVAL (Invalid argument)
write(2, "clock_nanosleep return value: ", 30) = 30
write(2, "22", 2) = 2
write(2, "\n", 1) = 1
write(2, "Testing CLOCK_THREAD_CPUTIME_ID "..., 33) = 33
write(2, "\n", 1) = 1
clock_getres(CLOCK_THREAD_CPUTIME_ID, 0x7fffe836d960) = -1 EINVAL (Invalid argument)
write(2, "clock_getres return value: ", 27) = 27
write(2, "-1", 2) = 2
write(2, " with errno ", 12) = 12
write(2, "22", 2) = 2
write(2, "\n", 1) = 1
clock_gettime(CLOCK_THREAD_CPUTIME_ID, {0, 15625000}) = 0
write(2, "clock_gettime return value: ", 28) = 28
write(2, "0", 1) = 1
write(2, "\n", 1) = 1
write(2, "clock_nanosleep return value: ", 30) = 30
write(2, "22", 2) = 2
write(2, "\n", 1) = 1
exit_group(0) = ?
+++ exited with 0 +++
There is a similar issue #2116 and User Voice idea https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/19349059-support-clock-process-thread-cputime-id-clocks related to fully support the clockid CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID , but I did not find any issue related to the full support of CLOCK_REALTIME, so I opened a new issue for this.
Activity
[-]`clock_nanosleep` with clockid `CLOCK_REALTIME` fails with error `EINVAL`.[/-][+]clock_nanosleep with clockid CLOCK_REALTIME fails with error EINVAL[/+]pmendham commentedon Nov 28, 2017
Problem seen independently and replicated on Windows 10 Pro, Version 1709, OS Build 16299.64
This issue currently means that WSL is not POSIX compliant because
CLOCK_REALTIMEis mandatory.peci1 commentedon Dec 6, 2018
ARgh, still the same problem on 1809... Took me quite some time to discover why everyting fails in my code...
therealkenc commentedon Feb 15, 2020
Moving the new landing zone to #4898.