Find the Parent PID of a Process on Linux with ps
Print the parent of a process with ps -o ppid= -p PID. The equals sign removes the header, and the value comes padded with spaces, so trim it in scripts.
A process is running and you want to know which one started it.
sleep 300 &
child=$!
echo "this shell is $$"
ps -o ppid= -p "$child"
ps -o pid=,ppid=,comm= -p "$child"
bash -c 'echo "subshell $$ has parent $PPID"'
ps -o ppid= -p "$child" | tr -d ' '
kill "$child"this shell is 595
595
596 595 sleep
subshell 599 has parent 595
595-o ppid= selects the parent PID column and the trailing equals sign gives it an empty heading, which removes the header line. In the run the background sleep reports 595, the PID of the shell that launched it. -o pid=,ppid=,comm= shows the process and its parent together, and in a script $PPID holds the parent of the current shell. The format options are in the ps manual.
The number is right-aligned with spaces, so strip them with tr -d ' ' or the shell, as the last command in the run does. A process whose parent has exited is adopted, and its parent PID becomes 1 or that of the nearest subreaper. The PID can be reused before you read it, so do not keep it for long.