top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Shutdown PC using C program?

0 votes
359 views

Can we shutdown the PC using C program if yes please help me?

posted Aug 22, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Yes, you can.

Inside your c program just call the "system(your_commnad)" .
Remember you have to run this program as supper user.

For example.

#include <stdio.h>
#include <stdlib.h>

int  main()
{
      printf("Going to shutdown the system....\n");

       /* 
           It will execute the "shutdown" command from the c program.
           You can provide "poweroff" in the place of "shutdown".
           To know more about system(), do a <man 3 system>.
      */
      system("shutdown -P now");  // see man shutdown for more options.
}
answer Aug 22, 2014 by Arshad Khan
Similar Questions
+1 vote

Given an array of integers (possibly some of the elements negative), write a C program to find out the *maximum product* possible by adding 'n' consecutive integers in the array, n <= ARRAY_SIZE.

Also give where in the array this sequence of n integers starts.

...