Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm implementing a Reboot() call in my application. It's an embedded application, so no console, keyboard or power switch. The Reboot() must eventually restart the system no matter what. Ideally, I want it to fail gracefully.

I've had systems in the past cause problems where a call to reboot or shutdown did not result in a reboot of the machine. e.g. failure to sync drives, unmount a removed USB flash drive.

My system is embedded, with a read-only mounted root filing system, so a sudden power off isn't a big issue. But I do write logs to a Flash disc and I'd like to preserve this as much as possible.

My current Reboot() looks like this:

void Reboot()
{
    system( "reboot" );     // try the reboot
    sleep(2);
    system( "reboot -f" );      // force
    sleep(2);
    system( "reboot -f -n" );   // force and don't try to sync
    sleep(2);
    system( "kill 1" );     // process 1 is the root process of all
    sleep(2);
    Reset();
}

The reset command is a hard system reset that will not fail. The system also has a Watchdog timer.

Would people care to comment on anything to add/replace/change in my Reboot() function?

e.g. should I use Magic SysRq?

share|improve this question
    
what about init 6 ? –  rkosegi Sep 17 '12 at 11:38
    
Sorry, I should have specified that I'm running Busybox. No run levels. But changing the run level, and calling the kill scripts just calls reboot command in the end anyway. –  Mr Stinky Sep 17 '12 at 12:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.