从程序重新启动linux [英] reboot linux from a program

查看:62
本文介绍了从程序重新启动linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前曾有人问过这个问题:如何从内部重新启动Linux一个C ++程序?

This question has been asked before: How to restart Linux from inside a C++ program?

但是,所有答案似乎都不适合我.

However, none of the answers seem to work for me.

这是我的问题:

我在一块硬件上有一个程序.我可以以root用户身份登录并运行它,而不会出现任何问题.但是,如果我以具有root特权的其他用户身份登录,则该程序可以正常运行,但不能正常启动.它只会关闭当前的Telnet会话.

I have a program on a piece of hardware. I can log in as root and run it without any issues. However, if I login as a different user with root priveleges, the program executes fine but does not reboot as it should. It only shuts down the current Telnet session.

要重新启动,我使用了 system(reboot).到目前为止,我已经尝试过:

To reboot, I've used system(reboot). So far I have tried:

sync();
reboot(RB_POWER_OFF);

还有

execl("/sbin/reboot","reboot",NULL,NULL);

无济于事.

(我不确定我是否正确使用了 execl .这是我第一次使用它.如果搞砸了,请纠正我).

(I'm not sure, if I've used execl correctly. It is the first time I use it. Please correct me if I messed up).

任何帮助将不胜感激.

/data/local/sbin # cat /etc/passwd
root:x:0:0:root:/root:/bin/sh
service:54zljpSAe:0:0:root:/root:/data/local/sbin/script

如果我以服务身份登录,则将运行脚本".用户有一个列表选项可供选择.一种选择是运行上述程序.

if I login as service, "script" will be run. The user has a list options to choose from. One of the options is to run the above mentioned program.

还值得一提:脚本中的选项之一是重新引导系统.如果从脚本内部调用,它将起作用.但是我想从程序中调用重启.

Also worth mentioning: One of the options in the script is to reboot the system. If called from inside the script, it works. But I would like to call reboot from the program.

推荐答案

首先,以具有root特权的其他用户" 登录到系统,并执行"init 6"(如果有)系统已重新启动?

first of all, login to your system as "a different user with root priveleges", and execute 'init 6', if system had been restarted ?

是:使用system("init 6");在您的程序中.

yes: use system("init 6"); in your program.

否:您遇到安全问题,首先必须解决该问题.

no: you have security issue, first you have to fix that.

这篇关于从程序重新启动linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆