Signals with trap

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
chakib

Signals with trap

Post by chakib »

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
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: Signals with trap

Post by xenopeek »

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 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Signals with trap

Post by rene »

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...
Locked

Return to “Scripts & Bash”