Skip to content

Instantly share code, notes, and snippets.

@gustavorv86
Last active October 3, 2019 06:13
Show Gist options
  • Save gustavorv86/1ccd6ee174e5c2edceb06e9c94fa277d to your computer and use it in GitHub Desktop.
Save gustavorv86/1ccd6ee174e5c2edceb06e9c94fa277d to your computer and use it in GitHub Desktop.
Function that pauses the execution of a program without affecting the signals.
#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