How to force system to reboot?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > How to force system to reboot?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    How to force system to reboot?  
banyan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-25-07 12:19 PM

I have a C program with root privilege running on MontaVista Linux. I
want to reboot the system after my program does a lot of file I/O. I
call system("/sbin/reboot") in one thread of the C program, but I found
it does not always work.

Although the followings are shown on the console, but the system stalls
sometimes. Is there a way to force the system to reboot in a C program?

==============================
The system is going down NOW !!
Sending SIGTERM to all processes.
Watchdog Release expect value 0
SOFTDOG: WDT device closed unexpectedly.  WDT will not stop!
uartClose.
idiom: closing misc device
udhcpd[283]: Received a SIGTERM

Sending SIGKILL to all processes.
==============================

I also found that directly run "reboot" command on the console shell
works almost all the time. So I think perhaps I can start my program in
a shell script, and run "reboot" command from there when a specific
exit status of my program returns. However, I don't know how to catch
an exist status of a C program in a shell script. Any pointer or
comment is appreciated.






[ Post a follow-up to this message ]



    Re: How to force system to reboot?  
Ralf Fassel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-25-07 06:19 PM

* "banyan" <banyan8@yahoo.com.sg>
| However, I don't know how to catch an exist status of a C program in
| a shell script.

#!/bin/sh
some_command
echo "The exit status of some_command is $?"
# End of file

HTH
R'







[ Post a follow-up to this message ]



    Re: How to force system to reboot?  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-25-07 06:19 PM

On 2007-01-25, banyan wrote:

> However, I don't know how to catch an exist status of a C program in
> a shell script.

The same way as you get the exit status from any program; it is
contained in $?.

--
Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
Shell Scripting Recipes:     |  My code in this post, if any,
A Problem-Solution Approach  |         is released under the
2005, Apress                 |    GNU General Public Licence





[ Post a follow-up to this message ]



    Re: How to force system to reboot?  
banyan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-26-07 06:34 AM

Thanks for the pointer.

However, my program has to run in the background, i.e. "my_c_program &"
appear in the shell script, otherwise other starting scripts following
my program won't run. And I found the echo line will not come out when
my program exits. Any suggestion for such case?

On Jan 25, 10:41 pm, Ralf Fassel <ralf...@gmx.de> wrote:
> * "banyan" <bany...@yahoo.com.sg>
> | However, I don't know how to catch an exist status of a C program in
> | a shell script.
>
>  #!/bin/sh
>  some_command
>  echo "The exit status of some_command is $?"
>  # End of file
>
> HTH
> R'






[ Post a follow-up to this message ]



    Re: How to force system to reboot?  
Gustavo Rondina


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-26-07 06:34 AM

"banyan" <banyan8@yahoo.com.sg> writes:

>Thanks for the pointer.

>However, my program has to run in the background, i.e. "my_c_program &"
>appear in the shell script, otherwise other starting scripts following

You can run the shell script in background, or you can use the
'wait' shell built-in command, which waits for the specified bg
process to finish before proceeding (it is shell dependant though).

--
Gustavo Rondina
http://gustgr.freeshell.org





[ Post a follow-up to this message ]



    Re: How to force system to reboot?  
Ralf Fassel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-26-07 06:18 PM

* "banyan" <banyan8@yahoo.com.sg>
| However, my program has to run in the background, i.e. "my_c_program
| &" appear in the shell script, otherwise other starting scripts
| following my program won't run. And I found the echo line will not
| come out when my program exits. Any suggestion for such case?

my_c_program &
my_c_program_pid=$!

..do other things...

wait $my_c_program_pid
echo "The exit status of my_c_program is $?"

R'





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:14 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register