Half a second is 500,000,000 nanoseconds, so your code should read:
tim.tv_sec = 0;
tim.tv_nsec = 500000000L;
As things stand, you code is sleeping for 1.0000005s (1s + 500ns).
More Related Contents:
- What is the proper #include for the function ‘sleep()’?
- How do I make this Linux program compile? [closed]
- Return value range of the main function
- When should I use mmap for file access?
- What is the equivalent to Posix popen() in the Win32 API?
- Connecting n commands with pipes in a shell?
- Atomicity of `write(2)` to a local filesystem
- GCC with -std=c99 complains about not knowing struct timespec
- Does printf always flush the buffer on encountering a newline?
- POSIX API call to list all the pthreads running in a process
- Kill Thread in Pthread Library
- Sleep function in Windows, using C
- Checking if a file is a directory or just a file [duplicate]
- Are there any platforms where using structure copy on an fd_set (for select() or pselect()) causes problems?
- How can I convert a file pointer ( FILE* fp ) to a file descriptor (int fd)?
- How to get the current time in milliseconds from C in Linux?
- implement time delay in c
- How to redirect the output back to the screen after freopen(“out.txt”, “a”, stdout)
- Create statically-linked binary that uses getaddrinfo?
- How to make parent wait for all child processes to finish?
- Is snprintf() ALWAYS null terminating?
- Redirect stdout to a file
- How is sleep implemented at the OS level?
- Is it possible (and safe) to make an accepting socket non-blocking?
- Posix regular expression non-greedy
- How to convert from UTC to local time in C?
- Difference between C standard library and C POSIX library
- Linux shared memory: shmget() vs mmap()?
- Checking if errno != EINTR: what does it mean?
- How to know if a Linux system call is restartable or not?