Yesterday while I was working on rc.local and ps documentation for the PLANET ARGON wiki I was distracted by the many many options to the procps version of ps. Even with all the options I had difficulty displaying exactly the information I wanted. For example displaying the environment that a process was running in was a BSD option, and the output formatting I wanted to use with it seemed to be a POSIX option that would kill all output of the environment.

It turned out that there was a simple solution to this. Write my own tool. It was simpler than that sounds. The /proc filesystem in linux is both nicely organized, and full of useful information.

Here is the full script I came up with.

#! /bin/sh
# Get environment for a process id from proc filesystem, 
# replace null characters with newlines, and
# print to the screen
cat /proc/$1/environ | gawk '{gsub("\0","\n");print}'

A useful mini app with just one line of code. Just run that with the pid numer after it to get the environment of that pid displayed just like it would be if you were at the terminal, and typed the “env” command. Thank you /proc. I would have thanked the authors of the linux implementation of /proc, but 5 minutes of google didn’t give me the information I was seeking.