May 2017
Beginner
552 pages
28h 47m
English
Well-behaved programs save data and shut down cleanly when they receive a SIGTERM signal. The trap command assigns a signal handler to signals in a script. Once a function is assigned to a signal using the trap command, when a script receives a signal, this function is executed.
The syntax is as follows:
trap 'signal_handler_function_name' SIGNAL LIST
SIGNAL LIST is space-delimited. It can include both signal numbers and signal names.
This shell script responds to the SIGINT signal:
#/bin/bash #Filename: sighandle.sh #Description: Signal handler function handler() { echo Hey, received signal : SIGINT } # $$ is a special variable that returns process ID of current # process/script echo My process ID is ...