DEV Community

loading...

How to get environment variables from a running process in Linux

bogdancornianu profile image Bogdan Cornianu Originally published at bogdancornianu.com on ・1 min read

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.

Discussion (0)

pic
Editor guide