LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-19-2017, 03:36 PM   #1
askfor
Member
 
Registered: Aug 2016
Posts: 75

Rep: Reputation: 44
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.
 
Old 04-19-2017, 05:40 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2 on Lenovo Thinkpad W520
Posts: 7,530

Rep: Reputation: 2481Reputation: 2481Reputation: 2481Reputation: 2481Reputation: 2481Reputation: 2481Reputation: 2481Reputation: 2481Reputation: 2481Reputation: 2481Reputation: 2481
See this old post.

Man xorg.conf for the details
 
Old 04-19-2017, 06:54 PM   #3
askfor
Member
 
Registered: Aug 2016
Posts: 75

Original Poster
Rep: Reputation: 44
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.
 
Old 04-19-2017, 08:14 PM   #4
qweasd
Member
 
Registered: May 2010
Posts: 589

Rep: Reputation: Disabled
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?
 
Old 04-19-2017, 08:40 PM   #5
askfor
Member
 
Registered: Aug 2016
Posts: 75

Original Poster
Rep: Reputation: 44
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 ?
 
Old 04-19-2017, 08:40 PM   #6
Gordie
Member
 
Registered: Aug 2007
Distribution: Slackware64 14.2, Kernel generic-4.4.75, Alien Bob's Plasma 5
Posts: 253

Rep: Reputation: 69
Perhaps the power moniter? I see something like that in the settings, on KDE anyway
 
Old 04-19-2017, 09:35 PM   #7
rob.rice
Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 998

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by askfor View Post
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
 
Old 04-19-2017, 10:05 PM   #8
montagdude
Member
 
Registered: Apr 2016
Posts: 575

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
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
user_suspend command:

Code:
#!/bin/bash

dbus-send \
  --system \
  --dest=org.freedesktop.UPower \
  --type=method_call \
  --print-reply \
  /org/freedesktop/UPower \
  org.freedesktop.UPower.Suspend
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.
 
3 members found this post helpful.
Old 04-19-2017, 10:06 PM   #9
bassmadrigal
Senior Member
 
Registered: Nov 2003
Location: Newport News, VA
Distribution: Slackware
Posts: 4,044

Rep: Reputation: 2033Reputation: 2033Reputation: 2033Reputation: 2033Reputation: 2033Reputation: 2033Reputation: 2033Reputation: 2033Reputation: 2033Reputation: 2033Reputation: 2033
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.

Last edited by bassmadrigal; 04-19-2017 at 10:10 PM.
 
Old 04-19-2017, 10:18 PM   #10
montagdude
Member
 
Registered: Apr 2016
Posts: 575

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Quote:
Originally Posted by bassmadrigal View Post
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.
 
Old 04-19-2017, 10:35 PM   #11
qweasd
Member
 
Registered: May 2010
Posts: 589

Rep: Reputation: Disabled
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.

Last edited by qweasd; 04-19-2017 at 10:41 PM.
 
Old 04-19-2017, 10:45 PM   #12
Gordie
Member
 
Registered: Aug 2007
Distribution: Slackware64 14.2, Kernel generic-4.4.75, Alien Bob's Plasma 5
Posts: 253

Rep: Reputation: 69
Quote:
Originally Posted by askfor View Post
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 ...
Attached Thumbnails
Click image for larger version

Name:	snapshot2.png
Views:	6
Size:	228.4 KB
ID:	24811  

Last edited by Gordie; 04-19-2017 at 10:50 PM. Reason: Hopefully to add an attachment - Never done this before
 
Old 04-19-2017, 11:19 PM   #13
qweasd
Member
 
Registered: May 2010
Posts: 589

Rep: Reputation: Disabled
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.
 
Old 04-19-2017, 11:51 PM   #14
montagdude
Member
 
Registered: Apr 2016
Posts: 575

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Quote:
Originally Posted by bassmadrigal View Post
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!
 
Old 04-20-2017, 08:43 AM   #15
askfor
Member
 
Registered: Aug 2016
Posts: 75

Original Poster
Rep: Reputation: 44
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.

Last edited by askfor; 04-20-2017 at 09:00 AM.
 
  


Reply

Tags
idle, suspend


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to suspend after idle or inactivity period without desktop environment or X? ineloquucius Linux - Newbie 5 11-20-2014 01:00 PM
LXer: Automatically Resume from Suspend to Ram and Suspend to Disk to Save Battery in Linux LXer Syndicated Linux News 0 05-10-2013 02:40 AM
Bash does not suspend/cancel pm-suspend theKbStockpiler Linux - General 1 11-05-2012 02:37 PM
pm-suspend vs. alternatives. gnome vs. enlightenment suspend. mkultra329 Linux - Newbie 1 02-19-2010 10:56 AM
Plz explain Suspend to Disk and Suspend to Ram pkhera_2001 Linux - Newbie 2 02-18-2008 07:23 AM


All times are GMT -5. The time now is 01:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration