DEV Community

Bogdan Cornianu
Bogdan Cornianu

Posted on • Originally published at bogdancornianu.com on

2

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay