Time, in a system programming context, doesn't only involve the act of measuring the duration of an event or reading the clock. It's also possible to put a process to sleep for a certain amount of time. This recipe will teach you how to put a process to sleep by using the seconds-based API, the microseconds-based API, and the clock_nanosleep() method, which has nanosecond resolution. Furthermore, we'll see what time overruns are and how we can minimize them.
Dealing with time sleep and overruns
How to do it...
In this section, we'll write a program to learn how to put a program to sleep by using the different POSIX APIs that are available. We'll also look at the C++ alternative:
- Open a shell...