Write program to shutdown a system in C/C++

C++Server Side ProgrammingProgramming

A program to shutdown the system works on the operating systems like windows, linux or macOS. To shut it off and close all opened applications.

What shut down or power off means?

Shut down or Power off a computer means removing power from a computer's main components in an organised prescribed way and turning off all the works that are done by the computer i.e. all applications and processings are shut off. After a computer is shut down, the main components such as CPU, RAM modules and hard disk drives are powered down, although some internal components, such as an internal clock, may access power.

This program turns off, i.e., shut down your computer system. System function of "stdio.h" is to run an executable file shutdown.exe which is present in C:\WINDOWS\system32 folder in Windows.

For Linux program the process is similar and is mentioned below.

For Windows

#include <stdio.h>
int main() {
   system("c:\windows\system32\shutdown /i");
   return 0;
}

The program works as a command that commands the operating system to close all applications and shutdown the system.

For Linux OS

#include <stdio.h>
int main() {
   system("shutdown -P now");
   return 0;
}

This is a code that can shut any linux based operating systems. Code directly puts a command for the system which executes it and shuts the system as soon as possible.

raja
Updated on 04-Oct-2019 07:54:57

Advertisements