Skip to content

Instantly share code, notes, and snippets.

@richlowe
Created February 5, 2016 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richlowe/20d40628e50162af9079 to your computer and use it in GitHub Desktop.
Save richlowe/20d40628e50162af9079 to your computer and use it in GitHub Desktop.
#!/bin/bash
eflag=
while getopts e opt; do
case $opt in
e) eflag=1;;
\?) printf "Usage: pargs [-e] <pid> ...]"; exit 2;;
esac
done
shift $(($OPTIND - 1))
cmdline() {
tr '\0' ' ' < /proc/$1/cmdline
}
environ() {
# XXX: Sadly, mawk doesn't accept \0 as RS, and treats it as RS=""
gawk 'BEGIN { RS="\0"; } { printf "envp[%d]: ", NR - 1; print }' < /proc/$1/environ
}
while (($# > 0)); do
echo $1: $(cmdline $1)
[[ -n $eflag ]] && environ $1
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment