Skip to content

Instantly share code, notes, and snippets.

@arindas
Created September 13, 2019 10:59
Show Gist options
  • Select an option

  • Save arindas/ef055c5e625d25bb5876c008e137b10e to your computer and use it in GitHub Desktop.

Select an option

Save arindas/ef055c5e625d25bb5876c008e137b10e to your computer and use it in GitHub Desktop.
List parent processes and their children from the output of `ps -ef`
#!/usr/bin/env bash
ps -ef | tail -n 20 > /tmp/10_procs
flag=0
mkdir -p /tmp/procs_folder/
while read -r uuid pid ppid _; do
if [[ flag -eq 0 ]]; then
flag=1
continue
fi
echo ${pid} | cat >> /tmp/procs_folder/${ppid};
done < /tmp/10_procs
for file in `ls /tmp/procs_folder`; do
echo "Parent ${file}:"
cat /tmp/procs_folder/${file}
done
rm -r /tmp/procs_folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment