24

Is there some equivalent (CLI or GUI) to Linux's /proc/$PID/environ feature?

26

You can inspect environmental variables of running process with

ps eww <PID>
| improve this answer | |
  • 3
    Is there a way to pretty print this afterwards? – Kevin Wheeler Jul 4 '16 at 21:48
  • I'm on macOS 10.14.4 and this doesn't work for me :( – Tran Triet Sep 23 '19 at 11:14
  • 1
    It works for me on macOS 10.15.1 – Andrew Dec 5 '19 at 1:53
12

The following adds on to Mateusz's answer, pretty printing the variables one per line:

ps eww -o command <PID>  | tr ' ' '\n'
| improve this answer | |
  • 1
    It's helpful and makes for a better answer if you explain what each component does. – Allan Sep 23 '16 at 23:15
  • 1
    If you're curious, explainshell can break this down. – Liam Dawson Dec 11 '18 at 0:35
  • This doesn't work if environment variable values have spaces in them – Les Hazlewood Oct 4 '19 at 20:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .