Tuesday, September 15, 2015

Linux Signal Types

 What is a signal ?

               Signal is a notification, a message sent by either operating system or some application to your program (or one of its threads).
     ex:  SIGINT that I already mentioned, tells your program that someone tries to interrupt it with CTRL-C.

from the command prompt you can list all the signal types like :


                               You’ll see that each signal type has a name (such as SIGINT, or just INT) and a number (2 in this case.) Out of a total of 64 signal types shown by kill -l , you’ll probably only need to deal with half a dozen or so,

Signal nameSignal valueEffect
SIGHUP1Hangup
SIGINT2Interrupt from keyboard
SIGKILL9Kill signal
SIGTERM15Termination signal
SIGSTOP17,19,23Stop the process

In this Signal Number 1,2,9 and 15 are the most used by the system administrator.

Open terminal and type :


1.Enter sleep command with a delay time (10000) running in the background (&)

Here you can see the result [1]  2486 which is the Job No and the Process ID.
 
2.Enter Kill  command with the process ID .

When you check the active  Process with the command ps -aux | grep sleep.we can see the sleep command is terminated.Here you can see the sigterm command executed default.

if you want to kill the command.then:



we can see that after giving the command :
 #Kill - 9 2549
The sleep command was killed. Signal (-9) is SIGKILL.

Control signals in Bash

Ctrl+CThe interrupt signal, sends SIGINT to the job running in the foreground.
Ctrl+YThe delayed suspend character. Causes a running process to be stopped when it attempts to read input from the terminal.
Ctrl+ZThe suspend signal, sends a SIGTSTP to a running program, thus stopping it and returning control to the shell.

No comments:

Post a Comment