Author Topic: Signals with trap  (Read 2624 times)

0 Members and 1 Guest are viewing this topic.

Offline chakib

  • Jr. Member
  • **
  • Posts: 1
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Signals with trap
« on: October 21, 2018, 02:20:10 pm »
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

Offline Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 17934
  • Karma: 461
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Re: Signals with trap
« Reply #1 on: October 21, 2018, 10:34:13 pm »
I'm pretty sure SIGKILL and SIGSTOP cannot be trapped (or handled at all).
https://www.shellscript.sh/trap.html
and
https://stackoverflow.com/questions/35569659/the-signals-sigkill-and-sigstop-cannot-be-caught-blocked-or-orignored-why

Ctrl+\ will send a SIGQUIT signal to the terminal, so maybe
Code: [Select]
trap "bash -c /usr/bin/gedit" 3
then Ctrl+\ should fire up /usr/bin/gedit
« Last Edit: October 21, 2018, 10:35:45 pm by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal