简单的Linux关机程序

来源:互联网 发布:淘宝尚领电动车能买吗 编辑:程序博客网 时间:2024/05/14 01:44
#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);
}
原创粉丝点击