I have a script which does ps -o comm= -p $PPID
.
The explanation says this gets the parent process name.
From the man page I found out -o
means user defined format, comm
means command and -p
means select the process by the given PID – in this case $PPID
, which means parent PID.
- What does
comm= -p $PPID
mean? - How does this command work?
Best Answer
-o comm=
means user output should be the command name only, but without any column title. E.g. if you do-o comm=COMMAND
, it will print you a column titleCOMMAND
:-p $PPID
selects the process by the given parent'sPID
, thePPID
.That means
-o comm= -p $PPID
are two independent options.So your command essentially does give you the name of the parent process by it's
PPID
.E.g. if I start
tmux
, it has thePID
of 1632. Now I start severalbash
in each pane, which each have the PPID of 1632, but have their own PID.Learn here more abut
PID
andPPID
s.I am not sure, but
ps
might look at/proc/$PPID/comm
to determine the parent's command name.In my case, executing this command gives you the name of the parent's process, without using
ps
: