How can I get the following information for a running Linux process:
- shell environment variables
- working directory
- command line options
You can get this information from /proc filesystem, it stores information about running processes.
cat /proc/<pid>/environ
cd /proc/<pid>/cwd; pwd -P
cat /proc/<pid>/cmdline
If you output the environment as suggested by @atype, you get all environment variables and their values concatenated without separator.
For better output, use
$ xargs -0 -L 1 echo < /proc/21645/environ
LANG=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
SHELL=/bin/bash
TERM=xterm
LC_MESSAGES=en_US.UTF-8
LANGUAGE=en_US.UTF-8
(output shortened for privacy reasons)
/proc/$pid/environ contains the environment variables as a null-separated list.
xargs is a tool to read a arbitrarily long list from *STDIN and feeds its elements to a tool (echo in this case) ensuring to not exceed the maximum command line length. The parameter "-0" switches xargs to use null as item separator (instead of the default blank or newline), The parameter "-L 1" limits the number of items to 1. Thereby each environment variable is output on a new line.