A simple CLI digital clock

We humans are quite used to seeing a clock tick away, one second at a time. Why not write a quick C program that mimics a (very simplistic command-line) digital clock that must show us the correct date and time every single second! (Well, personally, I prefer seeing the old-fashioned analog clocks, but, hey, this book does not go into the closely held secret mantras to perform graphical drawing with X11.)

How we achieve this is quite simple, really: we set up an interval timer that times out every one second. The program (ch13/intv_clksimple.c) which demonstrates the basic usage of the quite powerful setitimer(2) API follows.

For readability, only key parts of the source code are displayed in the following; to view ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.