C Program to Shutdown Computer in Linux

This is a C program to shutdown or turn off the computer in linux.

Problem Description

This program is used to shutdown or turn off the computer in linux.

Problem Solution

1. Use function system(“shutdown -P now”) to shutdown or turn off the computer in linux.
2. Exit.

Program/Source Code

Here is source code of the C Program to shutdown or turn off the computer in linux. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C Program to Shutdown or Turn Off the Computer in Linux.
  3.  */
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8.     system("shutdown -P now");
  9.     return 0;
  10. }
Program Explanation

1. Use function system(“shutdown -P now”) in the main function to shutdown or turn off the computer in linux.
2. Exit.

advertisement
advertisement
Runtime Test Cases
 
shutdown: Need to be root

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.