Created
September 13, 2019 10:59
-
-
Save arindas/ef055c5e625d25bb5876c008e137b10e to your computer and use it in GitHub Desktop.
List parent processes and their children from the output of `ps -ef`
This file contains hidden or 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
| #!/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