7

What is the difference between running startx and starting your display manager with sudo service (display_manager) start? Two different events happen, so I am curious as to know the difference behind-the-scenes.

  • You can launch an X server without a display manager AFAIK – Rui F Ribeiro Jan 10 '16 at 18:48
8

The graphical user interface on traditional Unix systems, as well as most modern Unix systems other than Mac OS X, is built on the X Window System. One component, the X server, communicates with the hardware (display and input peripherals) and offers basic primitives to display windows and route user input. Other programs, said to be X clients, display windows and listen to user input by communicating with the X server.

In order to talk with the hardware, an X server may require special privileges; for example, on some systems, the X server is setuid root. Recent systems try to avoid having the X server run as root in order to improve security. Depending on the system, running an X server on the system console may be restricted to certain users, or to the user with physical access to the console.

The X server alone does nothing but display a hard-coded background pattern and a mouse cursor. In order to do anything useful, some clients need to be started, typically including a window manager.

The normal way to run a GUI session is to run a session manager program, which takes care of launching all desired clients (window manager, desktop widgets, clipboard manager, restored programs from the user's previous session, etc.). The session manager needs to be started after the X server since it will interact with it. Each desktop environment comes with its own session manager; just about any window manager can also be used as a session manager, and in a pinch a terminal running a shell can be seen as a minimalistic session manager — what matters is that the user has some way to launch the programs they want to run.

There are two traditional ways to launch a GUI session:

  • If a user is already logged in, but they don't have a GUI yet, they can run the xinit command. This command starts an X server, then starts a session manager, and waits for the session manager to exit; then it kills the X server. This way, the client side of the session and the X server have the same lifetime. The startx program is a small wrapper around xinit.
  • It's also possible to start a GUI before any user is logged in. In that case, the only client is a display manager, which provides a login prompt. Once a user has logged in, the display manager invokes their session manager. When the session manager exits, the display manager ensures that no more programs are running in that session, and shows a new login prompt.

Another way to see this is that in order to have a graphical login session, there needs to be a graphical interface and the user needs to log in. These two steps can be performed in either order: login then start the GUI (startx method), or start the GUI then login (display manager method).

Other setups are uncommon but possible. For example, in a kiosk setup, the system startup scripts start an X server and a single full-screen client. In an autologin setup, the display manager runs a session manager for the default user at boot time.

  • 1
    What is difference between startx and xinit? – Rohan Feb 4 '16 at 22:07
2

Generally, a unix system requires root to start X (or a display manager, which runs within X).

Without a display manager, if root starts X then the current user of the X session is root.

With a display manager, root starts X and the display manager, but then allows other users to start sessions within that environment. This means that even though it took root to start X, a "normal" user can now take control and run all the processes safely.

Root, however, still "owns" the X session. Unless you have granted a user permission (by adding that user to the appropriate group) to do big important things like Shutdown or Restart, the user is not able to stop X. Only root can do that. That's sometimes important on a multi-user system, where you don't want users to suddenly decide to restart the machine, destroying other sessions in the process.

  • So for me to terminate my GUI session and go to virtual console, I have to run sudo service mdm stop to stop the display manager. Is there a way for me to just terminate X? By the way, I don't have to be root to start X. Is that not a requirement anymore to be root to start X? – Rohan Jan 10 '16 at 19:11
  • Pretty much everything regarding permissions can be changed, either by you (if you have root powers) or by your distro or sys admin. You may have been given permission to start and stop X by your sys admin or your distro. Technically you can just stop X (display manager included) but usually distros have it set so that if you do kill X, it will automatically start again. It's a sort of failsafe mechanism to make sure the user has a GUI. Not all distros do this (Slackware, for instance). You can also change the behaviour in Upstart or Systemd or whatever init you use. – Klaatu von Schlacker Jan 10 '16 at 20:25
  • 1
    This answer is very misleading, it implies that unprivileged users cannot run startx. – Gilles Jan 10 '16 at 23:15
  • 1
    @Gilles this is why I use the term "generally" and the phrase "unless you have granted a user privilege", and then the phrase "Pretty much everything regarding permissions can be changed" in my comment. I do not see this as misleading; I am answering in the context of the question and am not claiming to speak for all unices in every implementation. – Klaatu von Schlacker Jan 11 '16 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.