Skip to content

Instantly share code, notes, and snippets.

@pankkor
Last active July 4, 2025 12:17
Show Gist options
  • Select an option

  • Save pankkor/3299bbc9f2465c25aca88c7c2fc10376 to your computer and use it in GitHub Desktop.

Select an option

Save pankkor/3299bbc9f2465c25aca88c7c2fc10376 to your computer and use it in GitHub Desktop.
Monitor specific process tree hierarchy with `pgrep` and `pstree`
#!/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