3

Linux x86-64 compiling and statically linking with gcc I have:

#include <sys/reboot.h>

if (str[0] == 'r')
  reboot(0x1234567);

but I can't seem to find the equivalent function call for shutdown. I'd also like to know the llvm function if different.

Rich Oliver
  • 6,001
  • 4
  • 34
  • 57
  • Check the documentation. http://linux.die.net/man/2/reboot . However, only call reboot() if you really, really know what you're doing - it does an unsafe shutown/reboot of your system - you'd have to defer to the /sbin/shutdown or /sbin/reboot command to do it safely. – nos Sep 19 '14 at 13:34

2 Answers2

6

From sys/reboot.h :

/* Perform a hard reset now.  */
#define RB_AUTOBOOT     0x01234567

[...]

/* Stop system and switch power off if possible.  */
#define RB_POWER_OFF    0x4321fedc

So reboot(0x4321fedc); or reboot(RB_POWER_OFF); should work.

Eric Fournie
  • 1,362
  • 8
  • 10
  • Ah so Shutdown is a special case of Reboot. Maybe because I started out as a windows user, I think of Reboot as being a special case of Shutdown. – Rich Oliver Sep 19 '14 at 14:26
0

Try

system("shutdown -h now");
arserbin3
  • 6,010
  • 8
  • 36
  • 52
0xDen
  • 86
  • 2
  • That didn't seem to work. The only things I have on the system are the kernel in the /boot directory and my statically compiled init file in the /sbin directory. – Rich Oliver Sep 19 '14 at 14:37