C/C++ program to shutdown a system?


Here we will see how we can shut down the system by writing a simple C or C++ code. The shutdown process varies in different OS. If we are Linux user, we can use this terminal command to shut down.

shutdown –P now

If we are using Windows system, we can use this command −

c:\windows\system32\shutdown /i

We will see the code for Linux and Windows

Example(Linux)

#include<iostream>
using namespace std;
int main() {
   system("shutdown -P now");
}

Example(Windows)

#include<iostream>
using namespace std;
int main() {
   system("c:\windows\system32\shutdown /i ");
}

Updated on: 30-Jul-2019

502 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements