Suspend on inactivity
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 ? |
Perhaps the power moniter? I see something like that in the settings, on KDE anyway
|
Quote:
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 Code:
#!/bin/bash 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. |
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. https://github.com/bassmadrigal/scri...e_screenoff.sh 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. |
Quote:
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 |
Here's what I could dig up for general scripting, without having to activate xscreensaver:
https://anonscm.debian.org/cgit/coll...idle.git/tree/ has the C code for detecting idle keyboard & mouse time which should work, since I can see the requisite includes. It's like literally several lines of C. https://stackoverflow.com/questions/...ivity-in-linux makes a reference to a perl module which allows to get a similar result. Now you can write a shell script that will periodically (like once a minute) check the idle time and suspend via DBUS after it goes over a cap. For taking care of videos, just ps ax | grep [m]player && echo mplayer is running, or along these lines. The rest of "inactivity" definitions are too subjective, so for things like a big build, you will almost certainly have to rig up something special. |
1 Attachment(s)
Quote:
|
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.
|
Quote:
|
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. |
All times are GMT -5. The time now is 06:26 PM. |