|
Home > Archive > Unix Programming > January 2007 > How to force system to reboot?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to force system to reboot?
|
|
| banyan 2007-01-25, 7:19 am |
| 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.
| |
| Ralf Fassel 2007-01-25, 1: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'
| |
| Chris F.A. Johnson 2007-01-25, 1: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
| |
| banyan 2007-01-26, 1: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'
| |
| Gustavo Rondina 2007-01-26, 1: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
| |
| Ralf Fassel 2007-01-26, 1: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'
|
|
|
|
|