It is **operating system specific** (or hardware specific if you are coding some kernel-like software like an OS kernel -see [osdev.org][1]-, in *freestanding* C).

<sup>I'm focusing on Linux in my answer below.</sup>

If you are coding on Linux (in *hosted* C, as all user programs are), you'll code your [event loop][2] around a multiplexing [syscall][3] like [poll(2)][4] (or perhaps the older [select(2)][5], which I usually don't recommend). You might use some event loop library like [libev][6] or [libevent][7].

If you are unfamiliar with most Linux syscalls (listed in [syscalls(2)][8]...), read [Advanced Linux Programming][9].


Reading and polling the terminal is tricky on Linux (because [tty][10]-s are quite complex). You probably want to use some library, like [ncurses][11], do make a terminal application.


If you want to code a GUI application, you'll practically use some [toolkit][12] framework like [Qt][13] or [Gtk][14]. They provide an event loop, and you'll need to register [callbacks][15].

If you want to have two programs (written by you) communicating, you'll need to use some [IPC][16] machinery, notably [pipe(7)][17]-s. You'll probably need some event loop in some (or both) of them.

For time-related issues, [poll(2)][18] (so all event loop libraries built above it) is given a delay. See also [time(7)][19].


 [1]: http://osdev.org/
 [2]: https://en.wikipedia.org/wiki/Event_loop
 [3]: https://en.wikipedia.org/wiki/System_call
 [4]: http://man7.org/linux/man-pages/man2/poll.2.html
 [5]: http://man7.org/linux/man-pages/man2/select.2.html
 [6]: http://software.schmorp.de/pkg/libev.html
 [7]: http://libevent.org/
 [8]: http://man7.org/linux/man-pages/man2/syscalls.2.html
 [9]: http://advancedlinuxprogramming.com/
 [10]: http://www.linusakesson.net/programming/tty/
 [11]: http://www.gnu.org/software/ncurses/
 [12]: https://en.wikipedia.org/wiki/Widget_toolkit
 [13]: http://qt.io/
 [14]: http://gtk.org/
 [15]: https://en.wikipedia.org/wiki/Callback_%28computer_programming%29
 [16]: https://en.wikipedia.org/wiki/Inter-process_communication
 [17]: http://man7.org/linux/man-pages/man7/pipe.7.html
 [18]: http://man7.org/linux/man-pages/man2/poll.2.html
 [19]: http://man7.org/linux/man-pages/man7/time.7.html