-5

Manpage of systemd says:

   --system, --user
       For --system, tell systemd to run a system instance, even if the
       process ID is not 1, i.e. systemd is not run as init process.
       --user does the opposite, running a user instance even if the
       process ID is 1. 

How can I run systemd as a process with pid 1 and with pid not 1?

What does a system instance with pid not 1 mean? Can it coexist with a system instance with pid 1?

Does a system instance mean a process whose euid/ruid is root?

Does a user instance mean a process whose euid/ruid is nonroot?

Thanks.

2

For starters

In UNIX systems (including Linux), all processes have a process identifier, or PID. This is a number used to refer to the process while it runs. Normally, it is not possible to predict which PID a process will have.

However, there is one special process that always has PID 1: The init process, which is the first process launched on the system during boot. In addition to launching all the important background processes, it has several other purposes/tasks.

systemd is one of several possible programs that can run as process 1. However, it has an additional feature where it can also run in a "per-user mode", managing the background processes required for that specific user (e.g., connection to a smartphone -- this requires a special server on Linux). Normally, it can tell what it is supposed to do from its PID. These command line switches allow you to override this.

For more information about why and how to do this, I recommend this page on the Arch Linux wiki. Despite Arch's reputation of being an elitist and difficult distribution, the documentation is very good and surprisingly accessible.

To answer your specific questions:

How can I run systemd as a process with pid 1 and with pid not 1?

To run systemd with PID 1, it must be your init program. Most Linux distributions make it possible to choose from several such services (others are SysV Init, Upstart, runit and OpenRC), but systemd is usually the default. Therefore, this probably already happens on your computer.

To run systemd with a PID other than 1, you simply run it under any other circumstance. Again, this likely already happens on your computer, as the mainstream distributions also use systemd in the aforementioned per-user mode. For some things you can do with that, see the Arch wiki page I linked above.

Does a system instance mean a process whose euid/ruid is root? Does a user instance mean a process whose euid/ruid is nonroot?

The UID and EUID of the system instance will always be 0 (root), so that it can give the programs it launches all the required privileges. On Linux (and most UNIX systems), it is very common to start with full privileges and then relinquish all but those you actually need.

However, there might be at most one per-user instance of systemd that also has UID 0: Remember that root is just another user. While most modern-day Linux distributions take steps to prevent that by default, it is very well possible to log in as root.

A final word of caution

Do not, under any circumstance, experiment with systemd, logging in as root, or anything else that is startup or root related, on a computer you use for important work.

0

The man will be corrected, I reported issue for it https://github.com/systemd/systemd/issues/12843

--system can not be used with PID different than 1.

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.