Pete's Linux Advent Calendar 2007

The 16th day

Find out the environment of a process

The /proc filesystem contains useful information about processes. This will print some information about a given process id
#!/bin/bash
pid="$1"
if [ ! -r /proc/$pid/cmdline ]; then
    echo cannot read process information >&2
    exit 1
fi
echo -n "cmdline: "
xargs -0 < /proc/$pid/cmdline
echo -n "cwd: "
readlink /proc/$pid/cwd
echo "Environment:"
xargs -0 -n 1 < /proc/$pid/environ

Pete's Linux Advent Calendar 2007

Valid HTML 4.01!

Comments? send mail to pkruse@arcor.de my monogram