Request Power Status Linux Machine Programmatically

On a Windows (R) computer, you can use the following function to request system power status:

BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS lpSystemPowerStatus); 

Is there something similar for a Linux machine?

+8
c ++ c linux
source share
1 answer

On most Linux systems, the acpid daemon constantly monitors ACPI events and typically writes information to / var / log / acpid or / var / log / messages. There is http://linux.die.net/man/8/acpid for it. acpid stores current ACPI information in / proc / acpi, although moving to / sys somewhere and / sys / power / state holds the current power state by looking at it (cat / sys / power / state). More information about ACPI is at http://acpi.sourceforge.net/documentation/sleep.html . JCM mentioned a command line tool for monitoring ACPI status called AcpiTool, available at http://sourceforge.net/projects/acpitool/ . I built it on CentOS and it works great. Just follow the instructions in your INSTALL file to install it - this requires a C ++ compiler, which is usually located on linux or if it is not installed using yum or apt.

dmidecode can perform many requests for low-level problems, including system power supply and controls, see http://linux.die.net/man/8/dmidecode

In collaboration with freedesktop.org, RedHat has developed and provides DeviceKit-power pre RH7, called UPower, starting with RH7. It consists of a daemon tool and a command line. The mask for her is at http://www.pkill.info/linux/man/1-upower/ . The command line tool's --dump option provides some useful information, but is rarely updated. Perhaps restarting the daemon will result in an update. The following is an example of CentOS 6 host output:

 ca:17: devkit-power --dump Device: /org/freedesktop/DeviceKit/Power/devices/line_power_ACAD native-path: /sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/ACAD power supply: yes updated: Tue Dec 23 20:28:27 2014 (866 seconds ago) has history: no has statistics: no line-power online: yes Daemon: daemon-version: 014 can-suspend: no can-hibernate yes on-battery: no on-low-battery: no lid-is-closed: no lid-is-present: no 

Most major PC vendors, such as Dell and HP, provide their own power management and monitoring applications, and I found it best to use them because they know how to request custom probes developed in HW and print out the complete diagnostics for their support.

+2
source share

All Articles