Skip to main content
5 of 13
added 250 characters in body
Basile Starynkevitch
  • 32.9k
  • 6
  • 90
  • 133

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

I'm focusing on Linux in my answer below.

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

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

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

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

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

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


If you are coding on a non-POSIX operating system like Windows, you need to learn how to write event loops on it, and what is the low-level system API. You'll probably find some library for that. There exist a few libraries (e.g. Qt & POCO - both for and in C++) which are cross-platform.

Basile Starynkevitch
  • 32.9k
  • 6
  • 90
  • 133