Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
c++ command to shutdown ubuntu computer?
i'm using c++ but don't know the command to shutdown my ubuntu lucid computer.
How would I shutdown or logout the ubuntu from my .exe i made from c++?
if u have nothing useful to say don't post
3 Answers
- 1 decade agoFavorite Answer
Okay ...
First to shutdown Linux you have to invoke a command to the shell
Many commands can do like: $ init 0
So we look for a way to call a terminal shell from inside our c++ application then send this command to that shell.
Many functions in c++ allow this. Lets use popen():
#include <stdio.h>
int main() {
extern FILE *popen();
/* popen creates a pipe so we can read the output
of the program we are invoking in terminal*/
if (!(popen("init 0", "r"))) {
exit(1);
}
Here we create a pointer to a file that will hold the output of the command (we don't need the output for the purpose in our hand). Then we use the method popen() to send the command as the first parameter as you see.
Notes:
1.This command (init) may need a root privilege to be executed. I don't know how to do this maybe you need to run your c++ application as root?
2.I didn't try this myself, i just did some search for my idea and this is what i came up with.
I hope this help you.
Source(s): For the command init: http://www.krishnababug.com/2009/04/what-are-init-... For calling a terminal command through c++ application: 1) http://www.unix.com/programming/77863-running-shel... 2) http://forums.devshed.com/c-programming-42/how-to-... - Anonymous1 decade ago
I don't believe there is one... What you want to do is call the program shutdown with root privileges and attribute now (sudo shutdown now) or hook into GDM and get it to do it. But I personally have no idea how to hook into GDM to spare you the sudo so I'm afraid you will have to ask someone from gnome...