Gcc and llvm shutdown Linux function from c code

Linux x86-64 compilation and static linking to gcc I have:

#include <sys/reboot.h>

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

      

but I can't seem to find an equivalent function call to shutdown. I would also like to know the llvm function if it is different.

+3


source to share


2 answers


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);

either reboot(RB_POWER_OFF);

should work.

+6


source


Try



system("shutdown -h now");

      

0


source







All Articles