I am building a rust application, when the application is running, I want to set an OS level flag (an ENV variable) saying.. MY_CUSTOM_APP_RUNNING=true
and set it to false when application stops!
Also, My application has 3 different features, I want my application to listen to the flag changes.
For example, if I run export MY_CUSTOM_APP_FEATURE_1=enable
, my application should listen to this change.
Are these 2 things possible? How should I approach to do this?
It would be a cherry on top, if I could do this for all OS!
CodePudding user response:
No. Environment variables are scoped to each individual process and cannot be changed externally, meaning your program cannot update its parent's process's variables, nor can the parent update your program's variables after it was launched.
I can conceive of some hacky ideas to get vaguely to what you want, but that wouldn't be helpful. Environment variables are not the mechanism of choice to communicate with a live program. You should opt for pipes/sockets or file-monitoring.