0

I want to know whether Trap command will be use to protect a file from SIGKILL (ALT+ F4) signal or not. If it is then the following command will does that?

trap ~/Desktop/left.py SIGABRT

I'm trying to abort the all signals which trying to close left.py.

Jolta
  • 2,620
  • 1
  • 29
  • 42
Prabhu Are
  • 23
  • 6

2 Answers2

1

ALT+F4 doesn't typically send a SIGKILL. If you're trying to prevent a process from being killed when its parent shell window is closed, you want something like...

nohup ~/Desktop/left.py &

...to trap the SIGHUP.

Or you can trap all signals (except SIGKILL and SIGSTOP) inside the script itself. Take a look at the Python signal module.

Aya
  • 39,884
  • 6
  • 55
  • 55
  • could you explain exactly what signal it sends when I press ALT+F4? – Prabhu Are Apr 14 '13 at 06:20
  • ALT-F4 inside a shell doesn't usually send any signal. Your window manager, though, probably sends a `SIGTERM` to the shell, which in turn sends a `SIGHUP` to all child processes of that shell. – Aya Apr 14 '13 at 09:52
0

Inside the program text of left.py you can do something like this:

trap "" INT

That is, do nothing when SIGINT is raised. You can use TERM too if you want. I'm not sure which signal exactly is raised by Alt+F4 on your platform, and you mention SIGABRT and SIGKILL as well; you cannot ignore SIGKILL.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436