Running Emacs in systemd's session.slice
I use Emacs and EXWM as my window manager. For this setup, running an
Emacs daemon as a systemd-user unit allows me to attach multiple
clients to this process (for instance, to work in the same session
through an SSH connection on my iPad), and have the daemon survive
restarts of my graphical session. However, all subprocesses started
from within Emacs—which are virtually all applications & shells on my
system—are then tracked within the same systemd scope. This means
that a single application consuming excessive amounts of memory can
bring down my entire user session (looking at you, Firefox). This post
documents how you can move this Emacs daemon from the systemd
app.slice
into the more appropriate session.slice
, and run
applications & shells from within Emacs in their own scopes in
app.slice
.