Last active
October 3, 2019 06:13
-
-
Save gustavorv86/1ccd6ee174e5c2edceb06e9c94fa277d to your computer and use it in GitHub Desktop.
Function that pauses the execution of a program without affecting the signals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> /* Needed for struct timespec */ | |
/** | |
* Pauses the execution of a program without affecting the signals. | |
* Note: Compile with '-std=gnu11'. | |
* | |
* @param millis Milliseconds to sleep. | |
*/ | |
void millisleep(int millis) | |
{ | |
struct timespec ts; | |
ts.tv_sec = millis / 1000; | |
ts.tv_nsec = (millis % 1000) * 1e6; | |
// See: man 2 nanosleep | |
nanosleep(&ts, NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment