linux-sysprog · beginner · ~15 min
Translate a signal name to its number.
Tools like kill -s map a signal name to its number. Build that lookup for a few common signals.
Implement int sig_number(const char *name) that returns the signal constant for a given name.
name: a signal name string.SIGINT, SIGTERM, or SIGKILL for those names; -1 for anything else.
sig_number("SIGINT") -> SIGINT
sig_number("SIGKILL") -> SIGKILL
sig_number("SIGNOPE") -> -1
name: a signal name string.
The matching signal constant, or -1 if unrecognised.
Recognise SIGINT, SIGTERM, SIGKILL.
#include <signal.h>
#include <string.h>
int sig_number(const char *name) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.