linux下c程序調用reboot函數實現直接重啓
#include <unistd.h>
#include <sys/reboot.h>
int reboot(int flag);
------------------------------------
1 #include <unistd.h>
2 #include <sys/reboot.h>
3 int main()
4 {
5 /* 同步磁盤數據,將緩存數據回寫到硬盤,以防數據丟失 */
6 sync();
7 return reboot(RB_AUTOBOOT);
8 }
vim /usr/include/sys/reboot.h
--------------------------------------------------
#define RB_AUTOBOOT 0x01234567
#define RB_HALT_SYSTEM 0xcdef0123
#define RB_ENABLE_CAD 0x89abcdef
#define RB_DISABLE_CAD 0
#define RB_POWER_OFF 0x4321fedc
1 sys_reboot() -->
2 kernel_restart() -->
3 kernel_restart_prepare()
4 machine_restart()
linux-2.6.21.7/include/linux/reboot.h
--------------------------------------------
#define LINUX_REBOOT_CMD_RESTART 0x01234567
#define LINUX_REBOOT_CMD_HALT 0xCDEF0123
#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
#define LINUX_REBOOT_CMD_KEXEC 0x45584543
#include <sys/reboot.h>
int reboot(int flag);
------------------------------------
1 #include <unistd.h>
2 #include <sys/reboot.h>
3 int main()
4 {
5 /* 同步磁盤數據,將緩存數據回寫到硬盤,以防數據丟失 */
6 sync();
7 return reboot(RB_AUTOBOOT);
8 }
vim /usr/include/sys/reboot.h
--------------------------------------------------
#define RB_AUTOBOOT 0x01234567
#define RB_HALT_SYSTEM 0xcdef0123
#define RB_ENABLE_CAD 0x89abcdef
#define RB_DISABLE_CAD 0
#define RB_POWER_OFF 0x4321fedc
1 sys_reboot() -->
2 kernel_restart() -->
3 kernel_restart_prepare()
4 machine_restart()
linux-2.6.21.7/include/linux/reboot.h
--------------------------------------------
#define LINUX_REBOOT_CMD_RESTART 0x01234567
#define LINUX_REBOOT_CMD_HALT 0xCDEF0123
#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
#define LINUX_REBOOT_CMD_KEXEC 0x45584543
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.