How to schedule the execution of a function in 5 seconds with C

1 Answer

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

void myFunction() {
    printf("Function executed after 5 seconds!\n");
}

int main() {
    printf("Waiting for 5 seconds...\n");
    
    sleep(5); // Pause for 5 seconds
    
    myFunction();
    
    return 0;
}


   
/*
run:
   
Waiting for 5 seconds...
Function executed after 5 seconds!
 
*/

 



answered Jun 23, 2025 by avibootz

Related questions

2 answers 118 views
118 views asked Apr 29, 2025 by avibootz
1 answer 121 views
121 views asked Apr 29, 2025 by avibootz
...