2

How can I see env vars of a running process? The solution from here doesn't seem to work:

➜  ~ TEST=test /bin/bash -c 'sleep 1000 && echo $TEST' &
[1] 27677
➜  ~ ps eww 27677
  PID   TT  STAT      TIME COMMAND
27677 s010  SN     0:00.01 /bin/bash -c sleep 1000 && echo $TEST

I'm looking for value test. This is Big Sur 11.6.5 BTW.

2
  • Can reproduce. However, if you execute the ps command with the pid of the sleep process, the environment does show up. Commented Apr 18, 2022 at 17:40
  • 1
    @glennjackman, in my case it doesn't show anything for sleep either Commented Apr 18, 2022 at 18:51

1 Answer 1

1

You cannot do that on current macOS for processes in general. The process needs the get-task-allow entitlement in order for you to be able to read its environment variables. The hardened bash on modern macOS does not have this entitlement.

For programs you make yourself, you can just add the entitlement. For others, you will have to manually add it and codesign the binary again. Luckily someone has already made a small utility script that automates that process.

You must log in to answer this question.

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