Reputation: 55
Whenever I give reboot command, my process is receiving SIGTERM signal and is handling it. I don't want to handle it if the SIGTERM is due to reboot.
Please suggest me any idea.
Is there any way to send kill -9
signal to my process when I do system("reboot")
?
I am using Cent OS (Linux).
Upvotes: 3
Views: 5365
Reputation: 55
I found a solution for my question above and just wanted to update here. In /etc/init.d there is a file "halt". This halt is executed only on runlevel 0 and 6. i added a line "pkill -9 processname" before it it sends SIGTERM to all the processes.
Upvotes: 0
Reputation: 2730
whenever i give reboot command,my process is receiving SIGTERM signal and is handling it. I dont want to handle it if the SIGTERM is due to reboot.
You may try to run /sbin/runlevel
in your signal handler (well, maybe process spawning is not even possible in a signal handler though) to get the current runlevel. Runlevel 6 is reboot.
Is there any way to send kill -9 signal to my process when i do system(reboot).
If your process is started by init scripts you can change the script so that stop is performed with kill -KILL
instead of something else.
I am using Cent OS(linux).
I don't know if the following applies for CentOS.
In Debian, all remaining processes (the ones alive after all kill scripts have been ran) are signaled by /etc/init.d/sendsigs
. If you have administrator access you can try to customize it so a specially named process (yours) get KILLed without TERMing before.
Still, all pids related in /run/sendsigs.omit
and all pids related in files in /run/sendsigs.omit.d/
don't receive any signal.
Upvotes: 1
Reputation:
If your process is issuing the command to reboot the system, clearly it knows that the reboot is coming. Have it set up appropriate signal handlers beforehand, e.g.
signal(SIGTERM, SIG_IGN); // or SIG_DFL to restore default action (terminate process)
system("reboot");
Your process will still eventually get killed (via SIGKILL
) right before the system halts, but that won't happen until a little later in the reboot process.
Upvotes: 0