List of common signals

 Number               

   Name                           

Meaning

1 SIGHUP          If a process is being run from a terminal and that terminal itself is closed/terminated then the process receives this signal and consequently terminates.
2 SIGINT It politely tells the program to terminate. Performs the same function as Ctrl+C. It’s up to the process whether it will listen to it or not.
9 SIGKILL Unlike other signals, the SIGKILL signal is never sent to the process. Instead, the terminal immediately kills the program and the program doesn’t get the time to save its data or clean up its work. Only use this as a last resort.
15 SIGTERM                 This is the default signal of the kill command
18 SIGCONT This will restore a process that was paused by a SIGSTOP or SIGTSTP signal
19 SIGSTOP This signal pauses/freezes the process. The process cannot choose to ignore it.
20 SIGTSTP It is similar to SIGSTOP but the process receiving this signal is under no obligation to listen to it. The process may choose to ignore it.

Shell Scripting – How to send Signal to a Processes

Signals allow the operating system to communicate with programs(or processes). There are about 30 standard signals implemented by the Linux OS.

We can send signals to processes via certain keyword strokes or by the kill or wait command.

Sending signals to foreground processes

Go to the terminal and start a process, say xlogo in foreground. Install xlogo if it is not present in your system.

$ sudo apt-get install x11-apps
$ xlogo

After running the process in foreground, the shell prompt will be unavailable.

  • Pressing Ctrl+C sends an Interrupt signal (SIGINT) to the process and the process terminates. Restart it.
  • Pressing Ctrl+Z sends a STOP signal (SIGTSTP) to the process which kind of freezes/pauses the process and the shell prompt returns.
  • After pressing Ctrl+Z, you can unfreeze the paused process by moving it to foreground via fg %jobspec command or to the background using bg %jobspec command.

Ctrl+C terminates. Ctrl+z pauses/stops. bg command continues the process in background

Sending signals to background processes

$ xlogo &

Send signals to the process via the kill command. You need the jobspec or PID (process ID) of the xlogo process running in background.

You can view the jobspec or PID using the job or ps command.

$ kill -SIGTSTP PID
$ kill -SIGCONT PID
$ kill -SIGINT PID

Sending SIGTSTP, SIGCONT and SIGINT signal to xlogo process having PID 25648

  • SIGTSTP signal pauses the process
  • SIGCONT signal continues the paused process
  • SIGINT signal terminates the process.

Similar Reads

Creating Shell Script

We will create an interactive bash script to send signals to a process and observe the status of the process. For demonstration, we will use a program named xlogo to which we will send signals from our bash script. It’s a program that displays the X Window System Logo....

List of common signals

Number                   Name                            Meaning 1 SIGHUP          If a process is being run from a terminal and that terminal itself is closed/terminated then the process receives this signal and consequently terminates. 2 SIGINT It politely tells the program to terminate. Performs the same function as Ctrl+C. It’s up to the process whether it will listen to it or not. 9 SIGKILL Unlike other signals, the SIGKILL signal is never sent to the process. Instead, the terminal immediately kills the program and the program doesn’t get the time to save its data or clean up its work. Only use this as a last resort. 15 SIGTERM                 This is the default signal of the kill command 18 SIGCONT This will restore a process that was paused by a SIGSTOP or SIGTSTP signal 19 SIGSTOP This signal pauses/freezes the process. The process cannot choose to ignore it. 20 SIGTSTP It is similar to SIGSTOP but the process receiving this signal is under no obligation to listen to it. The process may choose to ignore it....