LINUX如何编程实现机器重新启动啊!

mhorse 2005-03-14 10:34:55
我在程序中用system(“reboot”)系统调用函数,
可是机器没有任何反应,在终端通过敲键盘命令
reboot却可以重启,这是怎么回事呢?
听说程序必须是SGID才行,我chmod + s myappname,
加上S属性,可是还不行.
搞过的进来说说啊!我用的是嵌入式arm-linux
...全文
201 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gomo544409 2005-03-15
  • 打赏
  • 举报
回复
你这样调用就没有问题了
system("/sbin/reboot");
tengulre 2005-03-15
  • 打赏
  • 举报
回复
reboot 如果没用就用 shutdown -r now 吧.
cvsuser 2005-03-15
  • 打赏
  • 举报
回复
调用reboot()函数,具体要做什么,详细的看帮助吧
jellen 2005-03-15
  • 打赏
  • 举报
回复
我在FreeBSD上用shell写一个:

#!/bin/sh
echo "System reboot"
reboot

假设把上面内容保存为“qq.sh”,chmod +x qq.sh
然后用root权限执行:./qq.sh 系统成功重启!

Kernel_Don 2005-03-15
  • 打赏
  • 举报
回复
#include <signal.h>

kill(1, SIGINT);
sharkhuang 2005-03-15
  • 打赏
  • 举报
回复
extern int bb_shutdown_system(unsigned long magic)
{
int pri = LOG_KERN|LOG_NOTICE|LOG_FACMASK;
const char *message;

/* Don't kill ourself */
signal(SIGTERM,SIG_IGN);
signal(SIGHUP,SIG_IGN);
setpgrp();

/* Allow Ctrl-Alt-Del to reboot system. */
#ifndef RB_ENABLE_CAD
#define RB_ENABLE_CAD 0x89abcdef
#endif
reboot(RB_ENABLE_CAD);

openlog(bb_applet_name, 0, pri);

message = "\nThe system is going down NOW !!";
syslog(pri, "%s", message);
printf(bb_shutdown_format, message);

sync();

/* Send signals to every process _except_ pid 1 */
message = "Sending SIGTERM to all processes.";
syslog(pri, "%s", message);
printf(bb_shutdown_format, message);

kill(-1, SIGTERM);
sleep(1);
sync();

message = "Sending SIGKILL to all processes.";
syslog(pri, "%s", message);
printf(bb_shutdown_format, message);

kill(-1, SIGKILL);
sleep(1);

sync();

reboot(magic);
return 0; /* Shrug */
}
TangChin 2005-03-15
  • 打赏
  • 举报
回复
来晚了,就是路径的问题,我也遇到过。
hy1080 2005-03-15
  • 打赏
  • 举报
回复
ARM-linux与radHat一样,原因可能是向楼上说的那样,你没指定咱径,所以才出现的这个问题

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧