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

link|improve this question

64% accept rate
I've always found typing out my question on stackoverflow/superuser/serverfault helps me realize the solution without help. I guess it's an extension of Rubber Ducking en.wikipedia.org/wiki/Rubber_duck_debugging – Puddingfox Jun 8 '10 at 14:09
@Puddingfox I was recommended to keep adding information (if not duplicate) even if I found out answer myself. – Vi. Jun 9 '10 at 13:09
feedback

2 Answers

up vote 4 down vote accepted

Command line:

ps -p 1111 -o ppid=

Function:

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

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.

link|improve this answer
feedback

Read /proc/$PID/status. Can be easily scripted:

#!/bin/sh
P=$1
if [ -z "$P" ]; then
    read P
fi
cat /proc/"$P"/status | grep PPid: | grep -o "[0-9]*"
link|improve this answer
grep '^PPid:' /proc/$1/status | grep -o '[0-9]*' is all you need. (It is very uncommon for Unix tools to do the if [ -z ]; then read thing.) – grawity Jun 8 '10 at 11:12
@grawity It helps do do things like echo $$ | ppid | ppid | ppid – Vi. Jun 9 '10 at 13:04
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.