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”
Subscribe to Bogdan Cornianu’s Blog
Launched 2 years ago
Hi, my name is Bogdan and I'm a software developer. Welcome to my personal blog!
Here you'll find news, reviews, tutorials and how-tos on software related topics and from time to time also my thoughts on unrelated topics.