Find the answer to your Linux question:
Results 1 to 2 of 2
I have two c programs, one is a daemon, and the other reads some system information that varies over time and stores it in a environment variable. I want the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2012
    Posts
    12

    creating environment variable


    I have two c programs, one is a daemon, and the other reads some system information that varies over time and stores it in a environment variable. I want the daemon to read a specific environment variable in which is stored the information updated by the other program.

    I would like to know, how to create my own environment variable, and if two programs are serialized in terms of access to the same environment variable. Note only one program reads the variable and only one program writes to the environment variable.

    Thanks in advance.

  2. #2
    Just Joined!
    Join Date
    Aug 2012
    Posts
    12
    To answer my own question, I found that I could include the following statement in /etc/profile:

    export INTER="0"

    which would create and initialize the environment variable upon start up. I could then use it in any which way I pleased.

    Whether or not access to the variable is synchronized I still don't know. I know that race conditions won't arise in this scenario because only one process is writing to the variable and only one process is reading it. Nevertheless, I am curious as to whether a lock or semaphore is acquired by a process when attempting to access the variable.

    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •