How to get environment variables from a running process in Linux

In Linux, everything is a file. Even running processes are represented as files. You will find all the running processes in /proc/, with a separate directory for each process id.

ps aux | grep [process name]  # to get the process ID
cat /proc/[process ID]/environ | tr '\0' '\n'

What the above commands do, is:

  • Get the id of a process by name
  • print the contents of the “environ” file for that process
  • print each environment variable on a new line; tr stands for “translate”

Leave a Comment

Your email address will not be published. Required fields are marked *

8 + 5 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.