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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs