Current instance of Shell ignoring SIGTERM

Hello.

Could anyone tell me how can I configure a instance of Shell to ignore the SIGTERM signal? I would really appreciate.

Thanks.

use the trap statement

trap 'echo "SIGTERM RECEIVED"' 15
# rest of code ....

Well this should make the shell ignore the SIGTERM signal right? It kind of doesnt..

trap "" TERM

should work on recent systems; if TERM isn't recognized on your system, find the signal number for SIGTERM on your system by looking in your compilation environment's equivalent of /usr/include/sys/signal.h. On most systems SIGTERM will be signal #15 so:

trap "" 15

will ignore SIGTERM in your script.

trap is used to trap signals within a running script. So while your script is running, it can catch a signal received (except for SIGKILL).
However, when you fork a new process from within your script it has its own PID with its own signals. So something like this won't do what you want:

#!/bin/bash

trap 'echo trapped' SIGTERM
/bin/bash -i  #will fork a new process, parent script keeps running and doesn't get to process the signal received until this child process is finished and flow returns to the script
echo Done #you won't see this until /bin/bash is finished. If this script  received a SIGTERM, you will see the trap message before "Done"

AFAIK it is not possible to catch a signal sent to a running executable, without inserting the trap into its source code and recompiling.

So what you see (guessing, since you never posted your code on how you are calling the shell and how you specify the trap), is that shell process is forked with its own PID, and parent script that you are calling it waiting for it to finish before it can process the signals. You can see that by running the example above.

kill -l    # -l == lowercase ell

lists all of the signals your system supports, both name and number. /usr/include/sys/signal.h also has them if you want to know what they mean - as Don C mentioned.

The kill -l option originated in the C shell and was standardized by the POSIX standards and the Single UNIX Specification many years ago. The standard requires that the -l option on a command line with no operands list the names of the signals known on that system, but does not allow the signal numbers to also be included in that list. Older versions of the Korn shell did print both names and numbers, but David agreed with other developers writing the standards that having the numbers made it more difficult for shell script writers to process the output of this option. Recent versions of the ksh utility's kill built-in do not print the signal numbers. :slight_smile:

On older systems where the trap special built-in utility only accepts signal numbers (not signal names), it was common practice for the kill utility not to recognize the -l option either.

You can also use current versions of the kill utility to translate a signal number into a signal name. For example:

kill -l $((128 + 15))

will either print TERM or SIGTERM on systems where signal number 15 is SIGTERM. Obviously, you can also put the above command in a loop to map signal numbers to signal names on your system.