+ 1
Which header file supports sleep function in c?
7 Answers
+ 1
j On Unix OS you shall include the unistd.h lib and on Microsoft Windows OS Sleep is in windows.h, and both Windows's sleep() and Posix's sleep(3) aren't the same, they take different arguments
+ 1
Manav
mm, actually sleep is supported in SL with neither error or warning, but the environnement our code are executed on, maybe specify a range of time '1s 4 ex.' to the main thread, if the thread crossed this limit, the environnement will send a sigterm or something to terminat the thread, use this code and play with it to better anderstand
https://code.sololearn.com/cM89j1N47N0L/?ref=app
run it multi times, change params,..
+ 1
time.h is a headerfile having sleep function that can pause execution in seconds
If we want to pause in milli seconds there is function called delay this is also available in time.h headerfile
+ 1
Manav but who tell you that SL's os that runs your codes are windows based os, all are ubuntu if am not messtaking, so you should use unistd.h header instead,
also in order to write a cross platform program, always try to use somthing like this:
#ifdef _WIN32
#include <Windows.h> //or something_else
#else
#include <unistd.h>
#endif