Documentation: Architecture of Linux Session

d-busdocumentationsessionsystemd

I'm looking for a good overview documentation describing the the stack of
daemons and services involved in a modern Linux session. Although having read
various documentation about dbus, and systemd,
I still don't get the big picture.

In particular, I'm looking for answers to these questions (don't answer the
questions, they should only clarify what kind of documentation I'm looking
for):

  • After logging in, which process is the root of the user's session?

  • Which processes should be started, and why? I'm looking for a
    Desktop-agnostic answer, no matter whether Gnome, KDE, FVWM, or a simple
    shell is started.

  • What role do all these daemons play? Which of them would run alone, which
    depend on others? Which one should be started by whom, why, and for how
    long? And who should maintain that zoo?

I'm asking, because I found that I have a whole zoo of daemons running right
after booting: systemd-journald, systemd-udevd, dbus-daemon,
systemd-logind. But not enough: Apart from these, Running ultra-lightweight
PDF-viewer zathura further populates my session with dbus-launch,
dbus-daemon, at-spi2-registryd, and at-spi-bus-launcher, the latter
launching yet another dbus-daemon. None of them have been there before,
none has been invited, but they will stay around the house, giving me a creepy
feeling, until I log out. I'm sure I'm missing something here…

Another example: After login, I have a systemd running with my users UID,
but I have no idea what it should do (since version 206 I think I'm not
supposed
to use that
as session manager, right?). It has a child process (sd-pam), which I
failed to find documentation about.

What do they do? What is the idea behind this setup?

To clarify my perspective: In “the old days” it was enough to know that
login would launch my login shell (bash, executing ~/.profile), and
from that point I could continue building a session, depending on circumstances, maybe launching screen, or startx.

Best Answer

I am so fascinated by your question that I answered it on linuxintro. Here is the answer tailored for your question:

When a typical PC with Linux like Fedora, SUSE or Ubuntu boots up the steps will be as follows:

  1. BIOS runs self-check
  2. BIOS loads the boot sector and executes it
  3. Bootloader like grub or lilo is executed
  4. Bootmenu is shown (optional)
  5. Kernel is loaded
  6. Initial RAM disk is loaded
  7. Kernel is executed
  8. Kernel executes init
  9. init executes, depending on your distro, version and configuration

    • SysV init scripts or
    • systemd or
    • upstart

The sense of all these programs is to start services like

  • dbus that allows communication between applications so that one application can call functions from another running application. This is something usually not visible to users, e.g. an application calling the window manager to put its own window into focus
  • login that allows users to log in on the CTRL_ALT_F* terminals. Login's process as seen by ps -A will in case of systemd be systemd-logind (may again vary by distribution)
  • udev that has a lot of names, e.g. for me I find it with ps -A as systemd-udevd. It assigns e.g. the device handles in /dev/ to devices that you connect, e.g. a USB disk
  • cron that will execute commands based on a time table in /etc/crontab, and also has a "@reboot" feature to start commands on boot.

10) the login process, handled by systemd will wait for a log in on a virtual terminal, one is typically reachable by pressing CTRL_ALT_F1

11) typically and by default, the init process will now start the display manager, e.g. kdm (KDE display manager) or xdm

12) the display manager will now start the graphical system. There is practically no graphical system but Xorg (hildon is for embedded devices).

13) the display manager will advice the Xorg server to display a login screen


Now the startup is complete and the computer waits for the user to log in.


14) on user log in the display manager will start a desktop environment like KDE, GNOME or XFCE4. The root process for a user's KDE session will be called startkde, the root process for GNOME will be called gnome-session, the root process for XFCE4 will be called xfce4-session

15) KDE typically starts all executable files from ~/.kde/Autostart and the .desktop files from /etc/xdg/autostart (see scheduling tasks).

16) When the user has logged in graphically and clicks on an icon to open a console, typically bash will be executed. Bash will first execute .bashrc then

17) When the user opens a log in shell this means he needs to log in via password or an authorized key. He can do this on the CTRL_ALT_F1 console or by ssh'ing to a computer, e.g. localhost. Then the .sh scripts from /etc/profile.d and .bashrc will be executed.

Related Question