How to shutdown your computer in Linux and/or Windows?
The idea is to use system() in C. This function is used to invoke operating system commands from C program.
Shutdown/ Log off/ Restart a Windows OS
We will make use of system() from < stdlib.h > to perform a system operation with the help of a C program.To perform any of the afore-mentioned system operation we will code as:
The argument to the system function is the path to OS and /i is one of the entity from the vast options available to us.To view the options, we run cmd and type:
The shutdown command presents us with a list of options available for us.These are :
To perform different operations, we just replace the last “/path” in system() argument.The common operations are:
This article is contributed by Sahil Chhabra and Amartya Ranjan Saikia. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- system() in C/C++
- Amazing stuff with system() in C / C++
- Print system time in C++ (3 different ways)
- Timer in C++ using system calls
- Java System.exit(0) vs C++ return 0
- Hello World Program : First program while learning Programming
- Program for Sum of the digits of a given number
- Quine - A self-reproducing program
- Program to compute Log n
- Output of C++ Program | Set 10
- Output of C++ Program | Set 14
- Output of C++ Program | Set 16
- Output of C++ Program | Set 18
- Program to print last 10 lines
- Program to validate an IP address
- Write a C program that does not terminate when Ctrl+C is pressed
- Write a C program that won't compile in C++
- Write a program that produces different results in C and C++
- OpenCV C++ Program to play a video
- OpenCV C++ Program to blur a Video