setenv

I am using “setenv” in my program to set the value of a particular
environment variable.

However, after doing this , if I type in “env” at the command prompt, it
still displays the old value for this environment variable? Is this normal
behaviour or am i missing something?

Your suggestions are appreciated

Shashank

Shashank <sbalijepalli@precitech.com> wrote:

I am using “setenv” in my program to set the value of a particular
environment variable.

However, after doing this , if I type in “env” at the command prompt, it
still displays the old value for this environment variable? Is this normal
behaviour or am i missing something?

This is absolutely normal and expected behaviour.

The environment is inherited, that is copied, from parent to child when
a child process is created (when a program is run). The child can not
change the parent’s environment. It can change its own environment,
and this will be inherited by any children it then runs.

What are you trying to achieve?

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

What I am trying to do is have two independent applications (children , as
you pointed out) share and be able to access a certain environment variable.
If one of them makes a change to it, the other should see the change.

Thanks,
Shashank



“David Gibbs” <dagibbs@qnx.com> wrote in message
news:cl38ob$on7$2@inn.qnx.com

Shashank <> sbalijepalli@precitech.com> > wrote:

I am using “setenv” in my program to set the value of a particular
environment variable.

However, after doing this , if I type in “env” at the command prompt, it
still displays the old value for this environment variable? Is this
normal
behaviour or am i missing something?

This is absolutely normal and expected behaviour.

The environment is inherited, that is copied, from parent to child when
a child process is created (when a program is run). The child can not
change the parent’s environment. It can change its own environment,
and this will be inherited by any children it then runs.

What are you trying to achieve?

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

Shashank <sbalijepalli@precitech.com> wrote:

What I am trying to do is have two independent applications (children , as
you pointed out) share and be able to access a certain environment variable.
If one of them makes a change to it, the other should see the change.

Assuming you’re trying to have this happen dynamically and symetrically –
that is, both children running, either one could change the value, both
need to be able to see the value, probably the best way to do this would
be to stick the data/information in shared memory. (This may require
notification of change – or just check the shared memory each time
value is needed, depending on frequency of use. It will, also,
probably require synchronisation to prevent on process from updating
the contents half-way through the access by the other – probably
semaphores.)

If you know that one is going to be updating, and the other always
just looking at it, you could have the updater send a message to
the user of the environment variable with it.

If this is more of a dynamic configuration type thing, you may be
able to write a third program that checks what the value needs to
be, and returns that to the parent shell, which then exports the
correct value to be inherited by both the children.


The parent shell might do something like:

export YOUR_ENV_VAR = program_to_findit
program1 &
program2 &

And, program_to_findit would do something like:

env_value = function_to_find_it();
printf("%s", env_value);
fflush(stdout);

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

We use a “name server program” which records “NAME=VALUE”. Then other
programs can query the name server to find out the value of a given name.
It can also replace a name definition.

A simple QNX application. If you want a copy of this, please reply.

Jeff Adler
Automation Services.


“David Gibbs” <dagibbs@qnx.com> wrote in message
news:cl3ejt$p2$1@inn.qnx.com

Shashank <> sbalijepalli@precitech.com> > wrote:

What I am trying to do is have two independent applications (children ,
as
you pointed out) share and be able to access a certain environment
variable.
If one of them makes a change to it, the other should see the change.

Assuming you’re trying to have this happen dynamically and symetrically –
that is, both children running, either one could change the value, both
need to be able to see the value, probably the best way to do this would
be to stick the data/information in shared memory. (This may require
notification of change – or just check the shared memory each time
value is needed, depending on frequency of use. It will, also,
probably require synchronisation to prevent on process from updating
the contents half-way through the access by the other – probably
semaphores.)

If you know that one is going to be updating, and the other always
just looking at it, you could have the updater send a message to
the user of the environment variable with it.

If this is more of a dynamic configuration type thing, you may be
able to write a third program that checks what the value needs to
be, and returns that to the parent shell, which then exports the
correct value to be inherited by both the children.


The parent shell might do something like:

export YOUR_ENV_VAR = program_to_findit
program1 &
program2 &

And, program_to_findit would do something like:

env_value = function_to_find_it();
printf("%s", env_value);
fflush(stdout);

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

“Jeffrey Adler” <jeffadler.at.bigfoot.dot.com@nowhere.com> wrote in message
news:cm87nb$7u3$1@inn.qnx.com

We use a “name server program” which records “NAME=VALUE”. Then other
programs can query the name server to find out the value of a given name.
It can also replace a name definition.

A simple QNX application. If you want a copy of this, please reply.

Jeff Adler
Automation Services.

Isnt it what QNX4 data server (ds) does. Hum but it doesnt work over a
network

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:cl3ejt$p2$> 1@inn.qnx.com> …
Shashank <> sbalijepalli@precitech.com> > wrote:

What I am trying to do is have two independent applications (children ,
as
you pointed out) share and be able to access a certain environment
variable.
If one of them makes a change to it, the other should see the change.

Assuming you’re trying to have this happen dynamically and
symetrically –
that is, both children running, either one could change the value, both
need to be able to see the value, probably the best way to do this would
be to stick the data/information in shared memory. (This may require
notification of change – or just check the shared memory each time
value is needed, depending on frequency of use. It will, also,
probably require synchronisation to prevent on process from updating
the contents half-way through the access by the other – probably
semaphores.)

If you know that one is going to be updating, and the other always
just looking at it, you could have the updater send a message to
the user of the environment variable with it.

If this is more of a dynamic configuration type thing, you may be
able to write a third program that checks what the value needs to
be, and returns that to the parent shell, which then exports the
correct value to be inherited by both the children.


The parent shell might do something like:

export YOUR_ENV_VAR = program_to_findit
program1 &
program2 &

And, program_to_findit would do something like:

env_value = function_to_find_it();
printf("%s", env_value);
fflush(stdout);

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com