Question

I'm writing a program in C with a mind on cross-compatibility, but I don't think I'm going to be able to get away without at least some platform specific #ifdefs.

One of the required features is to be able to put the system into Suspend power mode. On Windows, with the appropriate OS config, this is accomplished by using the SetSystemPowerState() function (after an appropriate security dance prior to the call).

Is there a Linux function that will do the same thing? I suspect it's there but so far my searching is only picking up command line programs and not any headers or function signatures.

Était-ce utile?

La solution

Try to install pm-utils. look here

Depend on your Linux, you better use yum, apt-get, etc...

Then it would be something like: system("pm-hibernate") or system("pm-suspend")

Maybe you'll need to use a full path to the utility.

It is open source, so if you want to program it with c, open the sources and check how it done.

EDIT:

A c solution is to use d-bus look here

it is a c source code, check how the dbus-send.c (in the tools dir) is working (with the arguments below).

Build all, and all you need is to link with the libdbus.

cpmmand line to dbus-send tool:

dbus-send --system --print-reply --dest=org.freedesktop.Hal \
 /org/freedesktop/Hal/devices/computer \
 org.freedesktop.Hal.Device.SystemPowerManagement.Suspend \
 int32:0

Autres conseils

Make a file susp.sh and save

   dbus-send --system --print-reply --dest=org.freedesktop.Hal \/org/freedesktop/Hal/devices/computer \org.freedesktop.Hal.Device.SystemPowerManagement.Suspend \int32:0

Make a file resume.sh and save dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer \org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate

Now add:

   system("sh susp.sh");

To suspend and

   system("sh resume.sh");

To resume

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top