Last active
July 4, 2025 12:17
-
-
Save pankkor/3299bbc9f2465c25aca88c7c2fc10376 to your computer and use it in GitHub Desktop.
Monitor specific process tree hierarchy with `pgrep` and `pstree`
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
| #!/bin/sh | |
| help=" | |
| Monitor specific process tree hierarchy. | |
| Pass case instensitive name of a process as a first argument. | |
| USAGE: | |
| ./psmon.sh [proccess_name] | |
| " | |
| if [ $# -lt 1 ]; then | |
| echo "ERROR: provide process name to monitor!" >&2 | |
| echo "$help" >&2 | |
| exit 1 | |
| fi | |
| case "$1" in | |
| -h|--help) echo "$help"; exit 0;; | |
| esac | |
| while true; do | |
| pids="$(pgrep -i $1)" | |
| echo "" | |
| echo "------------------------------------------------------------" | |
| echo "$(date)" | |
| echo "------------------------------------------------------------" | |
| for pid in $pids; do | |
| pstree -ahpsT $pid | |
| echo "------------------------------" | |
| done | |
| sleep 1 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment