C Program to Shutdown Linux OS
C Program to Shutdown Linux OS
In this program :
- You need to be logged in as user for above program to execute otherwise you will get the message shutdown: “Need to be root”.
'-P'
option specifies you want to power off your machine.- You can specify minutes as:
shutdown -P "number of minutes"
Let see the below program
#include<stdio.h>
#include<stdlib.h> // to use system() function
int main()
{
printf("\n\n\t\tEduguru C Program to Shutdown Linux OS\n\n\n");
char ch;
printf("Do you want to shutdown your pc now(y/n)?");
scanf("%c", &ch);
if(ch == 'y' || ch == 'Y')
system("shutdown -P now");
return 0;
}