Signals are most simplest way to notify a process with an information code. This code number is signal number.
Each signal has different meaning and there are default action defined for each signals. Default action for every signal is to terminate the process.
Signal is a type of interprocess communication. These can come from operation system kernel to notify process has one or more critical errors.
This is used by shell to inform a process to take some actions or these can be sent by process itself.
Applications often execute valuable section and any type of interruptions are not desirable.
It is possible that user can interrupt a process with Ctrl+C which sends SIGINT and Ctrl+Break which sends SIGBRK.
Programmer installs a signal handler and prints a warning message and this prevents unexpected exit.
Alternatively programmer can set handler as SIG_IGN for those signals which programmer wants to ignore.
void signal(int, void (__cdecl *)(int));
SIGINT - Interrupt signal received by shell or user(Ctrl+C)*
SIGILL - Illegal instruction executed by CPU and task scheduler sets this signal
SIGFPE - Encountered floating point exception in FPU and
SIGSEGV - segment violation
SIGTERM - Software termination signal from kill
SIGBREAK - Break signal received by shell or user (Ctrl-Break)
SIGABRT - Abnormal termination triggered by abort call
Defined signal action codes
SIG_DFL(0) - default signal action
SIG_IGN(1) - ignore signal
SIG_SGE(3) - signal gets error
SIG_ACK(4) - acknowledge
signal() is the C library routine to install signal handler for a particulate signal. First argument is the signal code and next is the function pointer of the user handler.
User has options to install user defined handler or handler to ignore the signal or revert original signal to default action.
raise() is a library function to send a signal code to its own. It takes signal code as argument and sends the signal to the same process id. C library does not have any function to send a signal to other process.
Kill is a system to send a signal to a specific process id.
void signal_int(int sig_num)
printf ("Signal interrupt received\n");
void signal_brk(int sig_num)
printf ("Signal break received\n");
void signal_term(int sig_num)
printf ("Signal term received\n");
void signal_abort(int sig_num)
printf ("Signal abort received\n");
int main(int argc, char* argv)
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.