Linux – How to get parent PID of a given process in GNU/Linux from command line

command linelinuxpidprocess

Resolved before asked: cat /proc/1111/status | grep PPid

Best Answer

Command line:

ps -o ppid= -p 1111

Function:

ppid () { ps -p ${1:-$$} -o ppid=; }

Alias (a function is preferable):

alias ppid='ps -o ppid= -p'

Script:

#!/bin/sh
pid=$1
if [ -z $pid ]
then
    read -p "PID: " pid
fi
ps -p ${pid:-$$} -o ppid=

If no PID is supplied to the function or the script, they default to show the PPID of the current process.

To use the alias, a PID must be supplied.