usleep 只是没有等待任何时间, errno 变量指责正在将无效参数传递给函数,即使我使用 useconds_t 类型,我也会一遍又一遍地得到相同的错误。
我不知道这里发生了什么,这是我为一些测试制作的文件。
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
int main() {
unsigned int delay=500000;
int err=errno;
printf("%d\n", err);
usleep(delay);
err = errno;
printf("%d\n", err);
return 0;
}
strace 输出:
execve("./a.out", ["./a.out"], 0x7fffec458c30 /* 22 vars */) = 0
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffff9f5d4f0) = -1 EINVAL (Invalid argument)
brk(NULL) = 0x1757000
brk(0x17581c0) = 0x17581c0
arch_prctl(ARCH_SET_FS, 0x1757880) = 0
uname({sysname="Linux", nodename="DESKTOP-PRJN4N7", ...}) = 0
readlink("/proc/self/exe", "/mnt/c/Users/User/dmsh/gm/a.out", 4096) = 31
brk(0x17791c0) = 0x17791c0
brk(0x177a000) = 0x177a000
mprotect(0x4bd000, 12288, PROT_READ) = 0
fstat(1, {st_mode=S_IFCHR|0660, st_rdev=makedev(0x4, 0x1), ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(1, "0\n", 20
) = 2
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=500000000}, NULL) = -1 EINVAL (Invalid argument)
write(1, "22\n", 322
) = 3
exit_group(0) = ?
+++ exited with 0 +++