1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#! /bin/sh set -euf pid=$$ while :; do cd /proc/$pid cmdline=$(cat cmdline | sed 's/\0/ /g;s/ $//') ppid=$(grep PPid status | awk '{print$2}') printf '%5d %s\n' $pid "$cmdline" if [ $pid = 1 ]; then break else pid=$ppid fi done \ | tac