Sunday, 18 August 2013

how to share environment variables between shells like globals related to a master pid?

how to share environment variables between shells like globals related to
a master pid?

So, I need to share environment variables between shells, and that the
changes on the variables be promptly recognized by all shells, like global
variables. But they must be related to a master pid, so I can have 2 shell
scripts running, each being a master with same global variable name, and
it childs will only change the variable related to their master pid.
I use bash for scripting.
My current researches are these:
Modules
I read I could use modules project for that:
http://modules.sourceforge.net/, but I am having huge trouble trying to do
it, it seems to lack examples? also "modules" is a too generic word, very
hard to google about because mixes with many other things... after some
weeks my hands are still empty..
Simple text source file
I read also I should use a simple text file to store/update/read variables
from, as a source script file, using flock too to avoid concurrent
writing. But there are problems related to doing that, like concurrent
change of variable simultaneously by 2 shells.
Alternatively
I am aware that after a "global" variable is read by the shell, it will
keep that value until another read is made; and another shell may change
it in the mean while too...
May be a very fast external application could provide such storage and we
would not try to use environment variables as globals then? but my guess
is any sql solution will be too slow..

No comments:

Post a Comment