How to restart or shutdown the whole computer with a command inside a pthreads-process?
exec ("reboot"); ??
exec("shutdown now");??
How to restart or shutdown the whole computer with a command inside a pthreads-process?
exec ("reboot"); ??
exec("shutdown now");??
The Windows API to do stuff like this is ExitWidnowsEx.
It is not, normally considered polite to restart/shut down the machine programmatically tho'.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
thanks but I forgot to specify I need it for Linux!! I need a "clean" shutdown of course!!
I am talkinng of an industrial PC in an industrial application, not for the use of several users so SW shutdown and restart are needed!
The main process (multipthread) is written by me and a colleague and only a few other server daemons will be running (like ssh, ftp etc.)
Last edited by mynickmynick; 07-31-2008 at 01:21 AM.
system("init 1") will reboot the system. See http://unixhelp.ed.ac.uk/CGI/man-cgi?init+8
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Another (fast+forced+manual) way is (kernel must be compiled with magic sysrq keys):
So, basicly, you write 's' (sync), wait some time, write 'u' (remount ro), wait some time, and then write 'b' or 'o'. ('o' didn't test, but docs says it's for shutdown).Code:FILE *f=fopen("/proc/sysrq-trigger", "w"); if (f) { // s = sync // u = remount all read-only // b = reboot // o = halt fprintf(f, "s\n"); ... // sleep between steps ... fclose(f); // reached ??? }
EDIT: assuming, of course, you have all the system under control, and can afford this approach...
Last edited by rasta_freak; 08-07-2008 at 05:45 AM.
I suggest doing a "man init" to be sure. IIRC, "init 0" halts the system, "init 6" reboots, and "init 1" gets the system back to single-user mode.
thank you!!