You are not logged in.
Hi there,
I'm quite sure it's been asked and answered before, but really can't find anything.
My question is: I implemented suspending my archlinux-running laptop when idle for some time, but would like to avoid suspending if a download is ongoing. How can I have the system check such a thing?
Thanks a lot in advance for your help.
Offline
The big question is what are you using for the "download". If it's a dedicated program like wget, aria2 etc., you can simply check for any such active processes before suspending.
Offline
If you show us what are you doing then we may have a targeted answer.
For the best I would guess, you may look at either the PID of the download manager or the traffic on the computer ports, then tell the Upower to suspend the operations.
So what's your download manager and what is the power manager that you using ?
do it good first, it will be faster than do it twice the saint
Offline
A computer that does not download or upload anything. What a waste of hardware!
I don't know any particular software to do this, but you can detect low traffic on your network interface. See "/sys/class/net/your-interface/statistics/rx_bytes". If it doesn't change much through some time (like a minute), nearly nothing has been sent and you can assume download is complete. Of course iff nothing else is being downloaded and the download is not going at ridiculous low speed.
An example, prototipe script to achieve that:
#!/usr/bin/env bash
if (($# != 3)); then
echo "$0 interface time-step-seconds treeshold-kib" >&2
exit 1
fi
iface="$1"
timestep="$2"
threeshold="$3"
lastReading=$(cat "/sys/class/net/$iface/statistics/rx_bytes")
while true; do
sleep "$timestep"
currentReading=$(cat "/sys/class/net/$iface/statistics/rx_bytes")
speed=$(((currentReading - lastReading) / timestep / 1024))
lastReading=$currentReading
if ((speed < threeshold)); then
# Do whatever you want
exit 0
else
echo "Download speed: $speed KiB/s"
fi
done
To run on interface xyz, waiting 60s between tests and considering values under 100KiB/s as "no download":
script xyz 60 100
Last edited by mpan (2015-01-27 18:57:32)
Sometimes I seem a bit harsh — don’t get offended too easily!
Offline
One minute test is too long. The system may go suspended, meanwhile.
do it good first, it will be faster than do it twice the saint
Offline
This is actually intended to go the other way around: disable suspend until the threshold is hit, at which point it is reenabled.
But even without that, once per minute is frequency high enough. How many people have suspend set to a minute? It would be ridicoulous. And 60s is just an example - one can perform the test even at 1Hz, but I believe this would lead to too many false positives.
Of course some scriptless solution would be better, but since no one provided the answer, this is currently the only working option proposed in the thread.
Last edited by mpan (2015-01-28 07:58:17)
Sometimes I seem a bit harsh — don’t get offended too easily!
Offline