Last active
November 23, 2019 01:37
-
-
Save RichardBronosky/b4cb78201ae39745398824a071bfa4d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
pid_lineage(){ | |
ps -p ${1:-$$} -o pid,ppid,args | tail -n1 | \ | |
( | |
read pid ppid args | |
echo -e "$pid\t$args" | |
[[ $pid -gt 1 ]] && pid_lineage $ppid - | |
) | ( | |
[[ ${2:-} != '-' ]] && \ | |
column -t -s $'\t' || \ | |
cat | |
) | |
} | |
pid_lineage "$@" |
Hello Richard, I have came up with an endless loop when one of my top parent processes had parent pid set to itself instead of to 1.
To handle I changed:
[[ $pid -gt 1 ]]
to:
[[ $pid -gt 1 && $pid -ne $ppid ]]
Cheers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This now works for Linux and macOS.