parctl - parental control for parents
parctl [-bg color]
parctl monitors and limits computer usage ("tube time"). Programs like this are typically used to prevent children from spending too much time over their digital gadgets. The same paradigm has, however, proved to be effective with adult specimen as well, particularly middle-aged computer scientists.
The modus operandi is as follows. The user is given a fixed time quota called slack for every 24 hours. Whenever the user is interacting with the machine, parctl decreases the slack by the corresponding wall clock time. For example, if the user interacts with the machine for 30 minutes, parctl removes 30 minutes from the slack. "Interaction" is defined as "typing on the keyboard or using the mouse".
parctl resets the slack at a certain reset time each day. If the slack gets used up before that, parctl unconditionally suspends the machine by executing sudo pm-suspend
. After that, the machine will be practically unusable until the reset time: wake-ups from the suspend will soon cause a re-suspension.
If the user does not interact with the machine for a certain period of time, parctl goes to idle mode and stops consuming the slack. During idle mode, parctl assumes that the user is away from the machine. When the user starts interacting with the machine again, parctl ends idle mode and resumes slack consumption.
parctl displays the remaining slack continuously in a simple window, and warns the user if they are running out of slack. Note that parctl is an X11 application and hence requires a running X session: true terminal junkies are considered hopeless and unsalvageable.
The author acknowledges certain special cases which call for exceptions, such as intense Emacs hacking or other "critical system upgrades", when the system simply cannot be suspended. In such dire circumstances, the user can selectively disable the slack consumption by switching to grace mode. Of course, the real need for such a blunt measure should be sagaciously evaluated each and every time.
The author also acknowledges certain use cases where the user mostly sits around the machine, gazing and immersing whatever audiovisual or other electromagnetic energy is being emitted by the device. Such activity is called consuming, and parctl can be told when consuming is in progress. During consuming, parctl decreases the slack unconditionally, regardless of any physical interaction with the machine. In other words, parctl does not go into idle mode at all.
At startup, parctl opens a single window that continuously displays the remaining slack with one second precision. Window background color depends on the current mode:
Normal background color means least concern mode: there is ample slack remaining.
Yellow background color means vulnerable mode: only a fraction of slack is remaining.
Red background color means endangered mode: only a couple of minutes of slack is remaining.
Blinking yellow/red background color means critical mode: only tens of seconds of slack is remaining.
Green background color means idle mode: slack is not consumed until the user starts interacting with the machine again.
Blue background color means grace mode: slack is not consumed at all.
Grace mode can be toggled by clicking on the window with mouse button 2.
If parctl is consuming, the remaining slack is displayed in boldface font. Consuming can be toggled by clicking the window with mouse button 3.
Slack time, reset time, and thresholds for different modes can be configured in constants.pl. The default values are:
Slack time: two hours
Idle threshold: two minutes of inactivity
Reset time: 03:00 UTC. The reset time is configured as seconds after midnight.
Vulnerable mode threshold: 15 minutes of slack remaining.
Endangered mode threshold: 5 minutes of slack remaining.
Critical mode threshold: 2 minutes of slack remaining.
Set the window background color to color.
SIGINT and SIGTERM cause immediate termination. SIGHUP causes a re-evaluation of constants.pl.
The user must be allowed to run sudo pm-suspend
without separate authentication.
Copyright 2017 Petteri Hintsanen <petterih@iki.fi>
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
sudo(8), pm-suspend(8)