trap command in Unix

Could anybody tell me what the trap command does and how it performs the action it does. I had read the trap manual page but it is too concise that nothing is clear about it. Please tell how it works.

It catches a signal sent to the process. It takes action on the signal using the action defined in the trap command - instead of letting the signal take it's default effect on the process. Blocking a SIGINT signal from terminating the process, for example.

trap "echo 'interrupt singal recevied'" INT

This turns cntl-c into a harmless message on the console. It stops cntl-c (SIGINT normally) from making the process exit.

Some signals cannot be trapped (blocked is the right term)

1 Like