DEV Community

Bogdan Cornianu
Bogdan Cornianu

Posted on • Originally published at bogdancornianu.com on

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'
Enter fullscreen mode Exit fullscreen mode

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”

The post How to get environment variables from a running process in Linux appeared first on Bogdan Cornianu.

Top comments (0)