Linux Process Environment Variables: 3 Commands to Inspect Running Daemons

Quick Linux Tip #117:

Question: How do I see what environment vars a running daemon was started with?

Try: sudo cat /proc/3456/environ | tr '\0' '\n'

Info: Reads null-separated initial environment variables from the process proc entry and translates them into readable lines.

Examples:

  • $ sudo strings /proc/3456/environ  # Alternative method using strings to extract readable text
  • $ sudo ls -la /proc/3456/cwd  # Inspect the current working directory of the process
  • $ sudo readlink /proc/3456/exe  # Resolve the absolute path to the running binary

Note: /proc/PID/environ displays environment variables present at process startup, not current runtime changes. Since any root user can read these, avoid passing raw secrets via environment variables; instead, use secured systemd configuration files (EnvironmentFile) with restricted permissions (0600).




LinuxTeck.com
linuxteck:~$ sudo cat /proc/3456/environ | tr '\0' '\n'
LANG=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOME=/var/lib/mysql
USER=mysql
MYSQL_HOME=/var/lib/mysql
MYSQL_UNIX_PORT=/var/run/mysqld/mysqld.sock
TZ=UTC
PWD=/
SHLVL=1
_= /usr/sbin/mysqld

linuxteck:~$ sudo cat /proc/3456/cmdline | tr '\0' ' '; echo
/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #116: Inotifywait in Linux: Automatically Rebuild Projects on File Changes NEXT ARTICLE Quick Linux Tip #118: Linux Directory Comparison: 3 Commands to Verify Folders
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.