Search notes:

libc: sleep / nanosleep

sleep

#include <stdio.h>
#include <unistd.h>

int main () {
  for (int i=5;i>=0; i--) {
    printf("Sleeping for %d seconds\n", i);
    sleep(i);
  }
}
Github repository about-libc, path: /sleep.c

nanosleep

#include <stdio.h>
// #include <unistd.h>

#include <time.h>


int main () {
  const long nano__s =    1          ; /* One nanosecond  */
  const long micro_s = 1000 * nano__s; /* One microsocond */
  const long milli_s = 1000 * micro_s; /* One millisecond */

  for (int ms = 1000; ms >= 0; ms -= 50) {

    struct timespec duration;
    duration.tv_sec  = 0;
    duration.tv_nsec = milli_s * ms;

    printf("Sleeping for %4d milliseconds\n", ms);
    nanosleep(&duration, NULL);

  }
}
Github repository about-libc, path: /nanosleep.c

See also

The Standard C Library

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758201035, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/C-C-plus-plus/C/libc/sleep(77): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78