Signals with trap

Forum rules
Before you post please read how to get help
Post Reply
chakib
Level 1
Level 1
Posts: 1
Joined: Sun Oct 21, 2018 9:15 am

Signals with trap

Post by chakib » Sun Oct 21, 2018 9:16 am

Hello,

I am preparing a small class for students on signals with trap. I understood the use of this principle with the example on signal 2 SIGINT:

trap "echo hello" 2: which displays "hello" each time you press the shortcut ctrl + c.

On the other hand, I have difficulty assimilating the use of the following cases:

1. The effect of signal 3 SIGQUIT.

2. The effect of siganl 9 SIGKILL.

3. The effect of the signal 19 SIGSTOP.

Can you guide me with simple examples please?

Best regard

User avatar
xenopeek
Level 24
Level 24
Posts: 23220
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Signals with trap

Post by xenopeek » Sun Oct 21, 2018 10:12 am

You can find explanation of signals here: https://en.wikipedia.org/wiki/Signal_(I ... IX_signals

Ctrl+\ sends SIGQUIT. Would normally quit the process.

Ctrl+Z sends SIGSTOP. It's a job control command. Pauses the running job and returns user to the shell. jobs list all jobs and fg can be used to resume a paused job. See help jobs and help fg.

You can't trap SIGKILL or SIGSTOP in Bash I think.
Image

rene
Level 8
Level 8
Posts: 2401
Joined: Sun Mar 27, 2016 6:58 pm

Re: Signals with trap

Post by rene » Sun Oct 21, 2018 8:06 pm

xenopeek wrote:
Sun Oct 21, 2018 10:12 am
You can't trap SIGKILL or SIGSTOP in Bash I think.
Indeed; those two signals (and only those) can not in fact be caught by any program. Hence the use of kill -9 as a process sledge hammer...

Post Reply

Return to “Scripts & Bash”