Is there a way to change the environment variables of another process in Unix?

raldi picture raldi · Oct 15, 2008 · Viewed 38.9k times · Source

On Unix, is there any way that one process can change another's environment variables (assuming they're all being run by the same user)? A general solution would be best, but if not, what about the specific case where one is a child of the other?

Edit: How about via gdb?

Answer

An̲̳̳drew picture An̲̳̳drew · Oct 17, 2008

Via gdb:

(gdb) attach process_id

(gdb) call putenv ("env_var_name=env_var_value")

(gdb) detach

This is quite a nasty hack and should only be done in the context of a debugging scenario, of course.