sigaction, getopt

getopt()

for parsing

After parsing, validate and print usage message that explain how the program should be used:

Usage: myprog [-n] file...

optional argument:[], required argument:{}

sigaction()

to handle signals (notifications about events).

see: https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html

see: https://stackoverflow.com/questions/41474299/checking-if-errno-eintr-what-does-it-mean

static volatile sig_atomic_t quit = 0; // interrupts main loopstatic void onSignal(int signal) {
quit = 1;
}int main(int argc, char **argv) {struct sigaction sa;
memset(&sa, 0, sizeof(sa)); // initialize to 0
sa.sa_handler = onSignal;
sigaction(SIGTERM, &sa, NULL)
// error: sigaction returns -1while (!quit) {
...
}
return EXIT_SUCCESS;
}