I would like to run a rather CPU intensive task all the time when the system is not in interactive use but stop it when being used.
When run during interactive sessions, this might cause serious lag. Is it possible to do this?
The good enough approximation would be:
- start the task when screen is blanked
- stop it when it is unblanked
- start it on system start
- run it always when there are no users logged
- never run it (and kill it if running) when running on battery power.
For the last part I already found out I can follow the file /sys/class/power_supply/AC/online .
For screen blank, however, I am not able to find a reliable method.
Preferably this should work even without X windows running.
However, I am okay with a solution that only works in co-operation with X Windows. The task could be always run(with low priority) if there is no X windows running or nobody is logged in.
I found an almost solution by reading the status from the output of 'xset q'.
However, this requires:
- continuous polling of the output instead of watching status of a file via inotify
- X running ...
Does, for example, DPMS monitor off, when done by X windows, change/delete/create a file somewhere?
I am comfortable in writing upstart configuration files and whatever is needed.
I am familiar with Linux and have spent several years as sysadmin for Linux systems. However, this problem does not come up when administering servers.