PCRD (system daemon)

logo

A Unix system daemon providing a unified interface to control desktop parameters

PCRD stands for Parameters Control and Reporting Daemon.

I created PCRD as a replacement for a collection of small scripts and hacks I came up with to fill the obvious blind spots of window managers. WMs (like dwm I am personally using) do one thing only and that is showing windows on the screen. That makes them good since they are lightweight, stable and predictable. But it also requires extra code that will handle other tasks, like reporting battery level, suspending the machine, or routing ACPI signals. PCRD (with proper plugins) takes care of all that and more.

Implementation-wise, it is a IO::Async program which consists of three parts:

  • Daemon

    Heart of the project, it is ran as root, stays active indefinitely and creates a Unix socket file to communicate with clients.

    Daemon consists of features, which are grouped in modules.

  • User agent

    Connects to daemon and executes commands which should be run as desktop user (not root). This is required because many programs need either GUI environment or the GUI user to run properly.

  • Client

    Connects to daemon and executes features. A special script exists which executes a single command and prints its output - it allows to plug PCRD into any part of the system which allows to execute a custom command.

Each feature can be executed in read or write mode by the client, and can instruct user agent to execute some commands and get the results back. Features can also introduce timers to perform recurring actions over time, or hook into other features' execution. This is simple yet extremely powerful system which can be easily modified to perform a variety of tasks.

Creating this program, I wanted it to be capable yet stay lightweight. I enjoy long battery times, quiet fans and free RAM. While Perl is not the most efficient programming language, PCRD only takes around 50 megabytes of RAM and 0.3% of a single core of my i7 CPU, while doing all of the following:

  • measure remaining battery life, RAM usage, CPU usage
  • gather system info every 5 seconds to update GUI status bar
  • recognize GUI mouse gestures and execute associated programs
  • watch ACPI signals: sound buttons, brightness buttons, lid state
  • auto-suspend the machine and auto-lock after suspending
  • relay notifications to dunst