Skip to content

Instantly share code, notes, and snippets.

@ichengzi
Created March 31, 2023 06:01
Show Gist options
  • Save ichengzi/87269778a1746a5c4e04e1abcf38de72 to your computer and use it in GitHub Desktop.
Save ichengzi/87269778a1746a5c4e04e1abcf38de72 to your computer and use it in GitHub Desktop.
test linux sleep

test.c

#include <unistd.h>
void main() {
  sleep(5);
}
  1. gcc test.c -o test.out
  2. strace ./test.out

out

strace ./test.out
execve("./test.out", ["./test.out"], 0x7ffea75e6b50 /* 25 vars */) = 0
brk(NULL)                               = 0x55b534a49000
#....省略中间输出
nanosleep({tv_sec=5, tv_nsec=0}, 0x7ffc08dcebe0) = 0
exit_group(0)                           = ?
+++ exited with 0 +++
@ichengzi
Copy link
Author

sleep 时间可以稍微调大一些, 这样在输出nanosleep后会有明显的等待

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment