neo
neo

Reputation: 1009

Integrating Linux soft + hard reboot

I read here that using below command we can simulate hard reboot on Linux system:

echo 1 > /proc/sys/kernel/sysrq 
echo b > /proc/sysrq-trigger

But I wanted to add some soft reboot feature before the above command is executed such as SIGTERM, SIGKILL etc which are issued on soft reboot. Can any one suggest how can i do it using bash or C/C++. Also what are steps followed while doing soft reboot on Linux system?

Upvotes: 0

Views: 859

Answers (1)

Eric Fournie
Eric Fournie

Reputation: 1372

Simulating or using the SysRq key sequences to trigger a soft reboot is not necessary in most of the situations, you can instead simply use the reboot command in bash. In a C program, I would use system("reboot");. Of course you will need to be root to reboot the machine.

Edit: If you want to call these command after the necessay cleanup of a soft reboot, your best option is probably to call yourself the corresponding reboot scripts in /etc/rc6.d.

This would be distribution-dependant, on a debian or ubuntu it would look like this: /etc/rc6.d/S20sendsigs /etc/rc6.d/S40umountfs /etc/rc6.d/S60umountroot

You can choose the scripts that you think are needed (networking, killing the daemons...).

Upvotes: 1

Related Questions