Answer the question
In order to leave comments, you need to log in
Linux sleep signal?
Is there any way to find out the state of the system using C++?
One function needs to be executed before the system goes to sleep.
The function is designed to save the value and pull out the system time in order to correctly resume it later, since the program sometimes does not work as expected after waking up from sleep.
Answer the question
In order to leave comments, you need to log in
Everything can be done with shell scripts.
Create a file, for example, 10_myscript with the following content:
#!/bin/sh
case "$1" in
hibernate|suspend)
echo "Suspending myscript"
;;
thaw|resume)
echo "Resuming myscript"
;;
*)
echo "Unknown command"
;;
esac
exit 0
Once I asked a similar question, but I did not find any iron solution for all distributions. I did it through DBus and it suited me:
Subscribe
QDBusConnection::systemBus().connect("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "Sleeping", this, SIGNAL(SystemIsGoingToSuspend()));
QDBusConnection::systemBus().connect("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "Resuming", this, SIGNAL(SystemIsGoingToResume()));
QDBusConnection::systemBus().disconnect("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "Sleeping", this, SIGNAL(SystemIsGoingToSuspend()));
QDBusConnection::systemBus().disconnect("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", "Resuming", this, SIGNAL(SystemIsGoingToResume()));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question