3

I am running Debian 9 but this is a more universal Linux question.

I have an Intel NUC (i5-4250U) with integrated graphics. When I run memory-intensive tasks in the background my system lags graphically. I am using the built-in i915 driver. I have 16GiB of memory and at no time am I swapping to disk.

I would like to have this process pause when I am using my computer. The best way I can think of determining if my computer is in use is to query the status of the screen blanking mechanism.

The tasks I am running in the background deal with being paused (manually) with no ill effects. They take days to run so when I forget to unpause them I lose a lot of potential work.

Ideas?

Thanks!

Edit #1: I was running Wayland, but I switched back to X so I can use the "xprintidle" command, which returns the number of milliseconds since the user last did something.

Using this answer, I modified the bash script to pause/unpause a particular PID. It would be neat to specify part of a process name but I can work with the PID okay.

There is most certainly a better way to do it, but this works for now.

#!/bin/bash
pid=11677
idle=false
idleAfter=10000
while true; do
  idleTimeMillis=$(xprintidle)
  if [[ $idleTimeMillis -gt $idleAfter && $idle = false  ]] ; then
    kill -CONT $pid
    idle=true
  fi
  if [[ $idleTimeMillis -lt $idleAfter && $idle = true ]] ; then
    kill -TSTP $pid
    idle=false
  fi
  sleep 1
done
Xyzzy
  • 31

0 Answers0