问题描述
我如何编程引发Linux的系统关机或重启? preferably而不需要提升的权限。
How do I programatically trigger a system shutdown or reboot in Linux? Preferably without requiring elevated privileges.
在旧版本(如Ubuntu的10.04),我可以打电话给HAL的 org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
或重新启动
使用的D-Bus方法。参见:http://people.freedesktop.org/~dkukawka/hal-spec-git/hal-spec.html#interface-device-systempower.
On older releases (e.g. Ubuntu 10.04) I could call HAL's org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
or Reboot
methods using D-Bus. See: http://people.freedesktop.org/~dkukawka/hal-spec-git/hal-spec.html#interface-device-systempower.
然而HAL似乎是过时的,并且不是在Ubuntu 12.10 present。什么是当前的最佳实践这样做?
However HAL appears to be obsolete, and is not present in Ubuntu 12.10. What is the current best-practice for doing this?
推荐答案
您可以使用工具。它包含源$ C $ c代表不同的关闭,从ConsoleKit的为Gnome和KDE的API。
You can also take a look at the KShutdown utility. It contains source code for different shutdown methods, ranging from ConsoleKit to Gnome and KDE APIs.
这篇关于Linux操作系统:编程方式关机或重新启动计算机从用户级进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!