IPC – Linux Communication Signals

IPC – Inter-process Communication – is the way running programs can communicate with each other in a Linux system when there are conflicts or user has need to interrupt the running program. The following are a list of the various signals that the Linux Kernel handles. Most of us are familiar with several of them already. For example when you run kill -9 process ID runs the number 9 SIGKILL.

Number Name Default action Corresponding event
1 SIGHUP Terminate Terminal line hangup
2 SIGINT Terminate Interrupt from keyboard
3 SIGQUIT Terminate Quit from keyboard
4 SIGILL Terminate Illegal instruction
5 SIGTRAP Terminate and dump core (1) Trace trap
6 SIGABRT Terminate and dump core (1) Abort signal from abort function
7 SIGBUS Terminate Bus error
8 SIGFPE Terminate and dump core (1) Floating point exception
9 SIGKILL Terminate (2) Kill program
10 SIGUSR1 Terminate User-defined signal 1
11 SIGSEGV Terminate and dump core (1) Invalid memory reference (seg fault)
12 SIGUSR2 Terminate User-defined signal 2
13 SIGPIPE Terminate Wrote to a pipe with no reader
14 SIGALRM Terminate Timer signal from alarm function
15 SIGTERM Terminate Software termination signal
16 SIGSTKFLT Terminate Stack fault on coprocessor
17 SIGCHLD Ignore A child process has stopped or terminated
18 SIGCONT Ignore Continue process if stopped
19 SIGSTOP Stop until next SIGCONT (2) Stop signal not from terminal
20 SIGTSTP Stop until next SIGCONT Stop signal from terminal
21 SIGTTIN Stop until next SIGCONT Background process read from terminal
22 SIGTTOU Stop until next SIGCONT Background process wrote to terminal
23 SIGURG Ignore Urgent condition on socket
24 SIGXCPU Terminate CPU time limit exceeded
25 SIGXFSZ Terminate File size limit exceeded
26 SIGVTALRM Terminate Virtual timer expired
27 SIGPROF Terminate Profiling timer expired
28 SIGWINCH Ignore Window size changed
29 SIGIO Terminate I/O now possible on a descriptor
30 SIGPWR Terminate Power failure

All but two of these signals can have handlers that overwrite the default. The two signals that can’t be overwritten are the SIGSTOP and SIGKILL signals.

The following is an example program that overwrites the SIGING (cntl-c signal) and SIGTSTP (cntl-z signal). You can play around and overwrite the handler for any other linux signals.

[c]
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

void handler1(int sig)
{
printf("Not so simple — I can’t be stopped with a ctr-c!n");
}

void handler2(int sig)
{
printf("Nope — I refuse to be put in the background!n");
}

int main()
{
/* install the SIGINT handlers */
/* only code changes go right here! */
if (signal(SIGINT, handler1) == SIG_ERR)

/* install the SIGINT handlers */
/* only code changes go right here! */
if (signal(SIGTSTP, handler2) == SIG_ERR)
/* Don’t change rest of code */
printf("Just try to stop me!n");
while (1)
sleep(1);
}
[/c]

Leave a Reply

Your email address will not be published. Required fields are marked *