Skip to content

Instantly share code, notes, and snippets.

@tangnotes
Created August 13, 2021 17:28
Show Gist options
  • Save tangnotes/062e08d46ae3b3ed823c2f80d4a3b4cb to your computer and use it in GitHub Desktop.
Save tangnotes/062e08d46ae3b3ed823c2f80d4a3b4cb to your computer and use it in GitHub Desktop.
function getPPID() {
_pid0=$1
_pid=`ps --no-header -o pid -p $_pid0`
if [ "x$_pid" == "x" ]
then
echo "Error: $_pid0 does not exists"
return
fi
echo -n "$_pid > "
_ppid=`ps --no-header -o ppid -p $_pid`
if [ "x$_ppid" == "x" ] || [ $_ppid -le 1 ]
then
echo $_ppid
return
fi
getPPID $_ppid
}
getPPID $1
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment