Determine whether the current Linux uses systemd, SysVinit, or another implementation as PID 1.
Print only the process name.
Which command is correct?
The first user-space process is PID 1. Displaying its comm field with ps identifies the active init implementation.
Detailed explanation
ps -p $$ -o comm=Incorrect. $$ expands to the current shell's PID, not PID 1.
Incorrect. $$ expands to the current shell's PID, not PID 1.
ps -p 2 -o comm=Incorrect. PID 2 is not the initial process.
Incorrect. PID 2 is not the initial process.
pgrep initIncorrect. pgrep init may find names containing init and is not a direct PID 1 query.
Incorrect. pgrep init may find names containing init and is not a direct PID 1 query.
ps -p 1 -o comm=Correct. ps -p 1 -o comm= prints the name of PID 1.
Correct. ps -p 1 -o comm= prints the name of PID 1.
Try it yourself
An example you can run in a temporary verification environment.
ps -p 1 -o pid=,comm=Expected result
1とPID 1の名前。systemd、init、コンテナランタイム等、環境により異なるKey points
- PID 1 is the initial process
- $$ is the current shell
- The implementation varies by environment
Notes
- Environment: Linux / procps-ng
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.