ctimer

Creating a timer in C


How do I create a timer? A timer like the one in Visual Basic; you set an interval, if the timer is enabled, it waits until the time is up.

I don't want to use an existing library, because I want to know how it works.

So... How do timers work and what would be an example of code to create my own? - if it's not too advanced.

I want to create one for a Linux system.


Solution

  • You can do that

    #include <stdio.h>
    #include <unistd.h>
    
    int main() {
        printf("wait\n");
        sleep(3);
        printf("time elapsed\n");
        return 0;
    }