LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2009, 05:19 AM   #1
kantu
Member
 
Registered: Sep 2008
Posts: 77

Rep: Reputation: 16
poweroff in C


Hi,
I was trying to implement poweroff and reboot in C
How can it be done ?
 
Old 07-02-2009, 05:41 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by kantu View Post
Hi,
I was trying to implement poweroff and reboot in C
How can it be done ?
Take the source of 'poweroff' command and find the answer there.
 
Old 07-02-2009, 05:53 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
...else please show us what you've got already (if "trying" means you actually tried to code anything) and what the errors are, if any.
 
Old 07-02-2009, 10:12 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
  1. Quote:
    Originally Posted by Sergei Steshenko View Post
    Take the source of 'poweroff' command and find the answer there.
  2. Quote:
    Originally Posted by unSpawn View Post
    ...else please show us what you've got already (if "trying" means you actually tried to code anything) and what the errors are, if any.
With great enthusiasm, I vote for A.

At least on Slackware, this command (issued while logged in as root so that the PATH environment variable would have a convenient variable)
Code:
file $(which poweroff)
produced:
Code:
/sbin/poweroff: symbolic link to `halt'
Ok, then. It's the same program that does both, and it probably examines argv[0] to determine whether to power off or simply halt. So:
Code:
file $(which halt)
produced:
Code:
/sbin/halt: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped
Now I was getting somewhere.

I explored the source, and discovered that if you have the appropriate man pages installed and you do this at the command line:
Code:
man 2 reboot
then all will be revealed.

Hope this helps.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help:cannot poweroff VINSTAR Linux - Newbie 3 02-11-2008 09:49 AM
Poweroff digger95 Slackware 13 11-04-2007 07:43 AM
poweroff Poszukiwacz Ubuntu 2 08-17-2005 05:10 AM
how to poweroff ?? perdesiz Linux - Laptop and Netbook 5 12-29-2004 03:31 AM
poweroff praveen_2003 Linux - Software 1 07-13-2003 01:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration