Skip to content

Instantly share code, notes, and snippets.

@corpix
Created December 17, 2015 21:39
Show Gist options
  • Save corpix/dd4936ff60c9f8d52f0f to your computer and use it in GitHub Desktop.
Save corpix/dd4936ff60c9f8d52f0f to your computer and use it in GitHub Desktop.
{
leaf=$$
ps -eo pid,ppid,command | awk -v leaf="$leaf" \
'{parent[$1]=$2;command[$1]=$3;}
function print_ancestry(pid)
{
print pid " (" command[pid] ") child of " parent[pid];
if(pid!=1) print_ancestry(parent[pid])
};
END{\
print_ancestry(leaf)
}'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment