SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How do I make Slackware suspend on inactivity ? I know pm-suspend and similar commands and I can suspend when I want. However, how to make computer suspend itself after, let's say, 10 minutes of inactivity. How the "inactivity" is defined and how it can be determined ? How to make it safe, so computer would not be interrupted while doing something, like compiling code ?
I am using lightweight IceWM window manager, so KDE or XFCE or something "magic tricks" do not qualify as answers.
That was about monitor. I mean suspend the whole machine. pm-suspend does that. The problem is how to detect that machine is idle. I suspect it might be something about acpid. It has hooks for machine states, but they seem to handle switch button actions.
You should define inactivity. There's keyboard inactivity & mouse inactivity, is that good? Does for example watching a 1-hr long movie with mplayer count as 50 minutes of inactivity?
NO, absolutely not. Watching movie is activity. I don't want PC to suspend in the middle of the movie. Also, I don't want it to stop building a large Slackbuild or something. I know Windows XP could do it. Later versions too, probably, although I have never seen it. Mac too, probably. I remember that Windows XP could define what would shutdown (screen, disk, everything) after what amount of inactivity. However there was no way to define "inactivity". I have no idea what would Windows or Mac do if compiling large number of source files for couple of hours. Never tried it.
I've seen a script which processes output of 'w' command, but that works for terminal sessions only.
Keyboard & mouse inactivity is definitely a major condition.
Screen inactivity is also a good condition, especially combined with mouse and keyboard.
How to define a CPU inactivity ? There is always something going on. 'ps' and 'top' in batch mode ? There is always something going on. Highest CPU percentage lower than some threshold ? What if process is niced ?
NO, absolutely not. Watching movie is activity. I don't want PC to suspend in the middle of the movie. Also, I don't want it to stop building a large Slackbuild or something. I know Windows XP could do it. Later versions too, probably, although I have never seen it. Mac too, probably. I remember that Windows XP could define what would shutdown (screen, disk, everything) after what amount of inactivity. However there was no way to define "inactivity". I have no idea what would Windows or Mac do if compiling large number of source files for couple of hours. Never tried it.
I've seen a script which processes output of 'w' command, but that works for terminal sessions only.
Keyboard & mouse inactivity is definitely a major condition.
Screen inactivity is also a good condition, especially combined with mouse and keyboard.
How to define a CPU inactivity ? There is always something going on. 'ps' and 'top' in batch mode ? There is always something going on. Highest CPU percentage lower than some threshold ? What if process is niced ?
the easiest way would be to go into your desk top environment setting manager and turn blanking off manually then restart it manually when your build or move is done
the power manager has no way to tell your building something or watching a video all it can see is the keyboard or mouse
No, you do not need to use a fancy desktop environment to suspend after inactivity. You can do it with xscreensaver. Here is a script that I run on startup (with reference in the comments):
Code:
#!/bin/bash
# Suspends laptop 2 minutes after screensaver kicks in (as long as the
# screensaver is still running at that point).
# Template from arch linux forums:
# https://bbs.archlinux.org/viewtopic.php?id=147773
PAUSE=2m
function process ()
{
while read INPUT
do
case "$INPUT" in
BLANK*)
# Wait PAUSE and check to make sure it is blanked
sleep $PAUSE
local ISBLANKED=$(xscreensaver-command -time | grep ' blanked')
if [ "$ISBLANKED" != "" ]; then
user_suspend
fi
;;
esac
done
}
xscreensaver-command -watch | process
The basic idea is that the xscreensaver-watch sends status information to the process function. When the screen is blanked, this function waits 2 more minutes and then suspends the computer. So you need to set up xscreensaver to blank the screen if you want to use this verbatim. Otherwise, of course, you can modify the script to your liking.
I also have a script to change xscreensaver settings for whether I'm watching a movie (disable xscreensaver) or not (enable it). I bind them to a hotkey so the setting can be quickly changed based on what I'm doing.
Last edited by montagdude; 04-19-2017 at 10:10 PM.
I don't know of anything that will detect if your computer is doing something in the background like compiling.
The closest I can provide you would be a script I created to mute my sound when the screen went into standby (to prevent notifications from sounding at all hours of the night). You could modify it so that when it detects the screen has been put in standby, after a certain period of time (and probably checking to verify the screen is still off), it could run the pm-suspend command.
Maybe you could also add to the script to check the load average, and if it is high, prevent suspending the computer. But I don't think you're going to find anything ready-made. It will likely be a script that you need to create and run in the background to detect various things and then run the commands you want.
EDIT: montagdude, where were you when I created my script? :P That seems much more elegant than my solution. Although, I have the screensaver disabled, so it seems it wouldn't have worked without me enabling it.
Last edited by bassmadrigal; 04-19-2017 at 10:10 PM.
EDIT: montagdude, where were you when I created my script? :P That seems much more elegant than my solution. Although, I have the screensaver disabled, so it seems it wouldn't have worked without me enabling it.
EDIT: I can't take too much credit for the script. I found the basic concept on the Arch forums after searching and just modified it a little bit.
xscreensaver is mainly useful because it keeps track of mouse and keyboard activity. I don't think there's a way to make it automatically know when you're watching a movie or compiling something, but it's easy enough to change its settings programmatically. Here's the script I use for that, which just makes some automated changes to the ~/.xscreensaver file. This one may need to be tailored to the user's preferences, so consider it an example only.
Code:
#!/bin/bash
function print_usage()
{
echo "Usage: xscreensaver_controller OPTION"
echo "Options:"
echo " --powersave-off: Deactivate screensaver and dpms power management"
echo " --powersave-on: Activate screensaver and dpms power management"
}
MODE=$1
if [ $# -ne 1 ]; then
print_usage
elif [ "$MODE" == "--powersave-off" ]; then
sed -i 's/mode:\t\trandom/mode:\t\toff/' ~/.xscreensaver
sed -i 's/dpmsEnabled:\tTrue/dpmsEnabled:\tFalse/' ~/.xscreensaver
elif [ "$MODE" == "--powersave-on" ]; then
sed -i 's/mode:\t\toff/mode:\t\trandom/' ~/.xscreensaver
sed -i 's/dpmsEnabled:\tFalse/dpmsEnabled:\tTrue/' ~/.xscreensaver
else
print_usage
fi
Last edited by montagdude; 04-19-2017 at 10:27 PM.
NO, absolutely not. Watching movie is activity. I don't want PC to suspend in the middle of the movie. Also, I don't want it to stop building a large Slackbuild or something. I know Windows XP could do it. Later versions too, probably, although I have never seen it. Mac too, probably. I remember that Windows XP could define what would shutdown (screen, disk, everything) after what amount of inactivity. However there was no way to define "inactivity". I have no idea what would Windows or Mac do if compiling large number of source files for couple of hours. Never tried it.
I've seen a script which processes output of 'w' command, but that works for terminal sessions only.
Keyboard & mouse inactivity is definitely a major condition.
Screen inactivity is also a good condition, especially combined with mouse and keyboard.
How to define a CPU inactivity ? There is always something going on. 'ps' and 'top' in batch mode ? There is always something going on. Highest CPU percentage lower than some threshold ? What if process is niced ?
Hmm, we both posted at the exact same time so I didn't see this information. It changes things. I have Cairo-Dock installed. One function is to disable the screensaver. I use that when watching videos. Not sure if that would help you but ...
Last edited by Gordie; 04-19-2017 at 10:50 PM.
Reason: Hopefully to add an attachment - Never done this before
A fun fact, very related: my wife watches a lot of youtube in web browser, and there seems to be no bloody way to detect THAT activity. She uses KDE, but can KDE detect html5 video playing? I remember hitting a brick wall on that one I ended up setting her up with 2-hour suspend policy, enough to take care of most web videos. Even though it's fun to look things up, you can see above, I haven't really tested these ways, since I personally waste my time on getting my laptop to never initiate anything power-related at all My suspend, for example, is hooked to Tux+s, which is trivial to do in pretty much any window manager.
Maybe you could also add to the script to check the load average, and if it is high, prevent suspending the computer. But I don't think you're going to find anything ready-made.
Actually, now that I think about it, checking the average CPU load periodically in a script would probably be a good method to automatically enable or disable the screensaver. It should work for watching movies, listening to music, or compiling, as long as you can tweak the threshold correctly. Thanks for giving me a new idea to tinker with!
I did search on how KDE does power management. It looks like there is a daemon which is watching actual power consumption, and it triggers events. User can configure responses to those events, including "suspend session". One article suggests that there exist other deamons which do similar tasks.
So, the key seems to be actual power consumption by the system. There is a program called powertop, which is installed by default. I am looking into it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.