In the Linux system, implement the timer-general Linux technology-Linux programming and kernel information. The following is a detailed description. Implementing a timer in Linux is not as intuitive as in Win32. You can call SetTimer in Win32. in Linux, no corresponding function can be called directly. As a common function, the timer is also implemented in Linux. Next we will look at several common methods.
To implement the timer function, sleep/usleep is the most common method. Of course, it will block the current thread. In addition to the timing function, nothing can be done. Of course, it is not difficult to solve this problem. Create a separate thread to take charge of the timer, and other threads will take charge of normal tasks.
The easiest way to implement the timer function is to use the ALARM signal. This method is simple and has the corresponding drawbacks: Low Signal implementation efficiency; 1 second minimum accuracy, unable to implement a high-precision definer. Simple Example: