Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 526
raldi Avatar asked Oct 15 '08 15:10

raldi


People also ask

Can environment variables change during execution?

No. This is not possible. One process can never directly manipulate the environment of a different already-running process.


1 Answers

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.

like image 53
An̲̳̳drew Avatar answered Oct 18 '22 21:10

An̲̳̳drew