您的位置:首页 > 运维架构 > Linux

最简单的Linux关机命令程序

2008-11-26 17:29 447 查看
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/reboot.h>

int main(int argc, char **argv)
{
/* first disable all our signals */
sigset_t set;
sigfillset(&set);
sigprocmask(SIG_BLOCK, &set, NULL);

/* send signals to all processes _except_ pid 1 */
printf("sending SIGTERM signal to all processes\n");
kill(-1, SIGTERM);
sync();
sleep(3);

printf("sending SIGKILL signal to all processes\n");
kill(-1, SIGKILL);
sync();
sleep(3);

/* shutdown */
printf("system shutdown\n");
sleep(2);
reboot(RB_POWER_OFF);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息