In man 7 signal it says:
Code:
The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
So you cannot trap them. In order to show how they work you can use kill builtin in the script:
Code:
#!/usr/bin/env bash
printf "My PID: %d\n" "$$"
printf "Send SIGSTOP\n"
kill -STOP $$
printf "Send SIGKILL\n"
kill -KILL $$
After SIGSTOP is sent run fg to restore program execution and SIGKILL will kill it. You can also mention that you can use signal number instead of name with kill builtin, that signals and their usage are described in man 7 signal and that you can send signal from another process and that's what's usually done.
SIGQUIT can be invoked with ^\ as stty -a says (^ means Control key):
Code:
$ stty -a
speed 38400 baud; rows 65; columns 105; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>;
start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel
iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho
-extproc
You can use the following script:
Code:
#!/usr/bin/env bash
trap "echo SIGQUIT" QUIT
printf "My PID: %d\n" "$$"
printf "Press ^\\\\\n"
while true
do
sleep 1
done
We have to run sleep in a loop because in man bash it says:
Code:
If bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes.