In bash script I handle different signal as follows:
#!/bin/bash
sighdl () 
{
  echo "signal caught"
  #do something
  exit 0
}
trap sighdl SIGKILL SIGINT SIGTERM
Above code handle signal properly for following activity:
kill pidpkill scriptnameFor kill -9 pid it does not call sighdl. As per my understanding (if I am not wrong) kill -9 sends the SIGKILL signal.
Any idea?
You cannot do that. Yes 9 is SIGKILL and Unix system by design doesn't allow any script/program to trap SIGKILL due to security reasons. Otherwise any script can trap & ignore SIGKILL which will make impossible to terminate that script by OS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With