LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-27-2009, 10:58 AM   #1
linuxManish
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Rep: Reputation: 0
environment variable access across different process on the system


Hi,
Is there any way to access some of the environment variables of one process in another process ?

for example, a daemon running on the system has some environment variable exported. Now I'm writing a c++ utility that will run independently of the daemon, but it needs some of the environment variables of the daemon for its functionality. Since this utility is not the child process of the daemon process, it doesn't have any access to those environment variable. So, is there any way to access those variables ?

One way I thought was to somehow make this utility a child process of that daemon, but don't know how it can be done ?

Please enlighten on this.
Thanks
 
Old 02-27-2009, 11:24 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Even when there is a parent/child relationship between processes, the child only receives an independent copy of the parent's environment. Without using some planned interprocess communication (IPC), there is no direct way of sharing environment or any other part of a process's context. To make it any other way would be a security problem.
--- rod.
 
Old 02-27-2009, 11:40 AM   #3
linuxManish
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Original Poster
Rep: Reputation: 0
ok, barring security concerns, is it still possible to do something to get those variables ?
 
Old 02-27-2009, 11:59 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Yes, it is possible to share information of almost any sort (not just env vars) between processes. To do so requires the use of an appropriate IPC mechanism, and all participating process must be programmed to behave appropriately for the application. Simply peeking behind a process's curtain to see its environment variables cannot be done directly.
For a good primer on IPC, see Beej's Guide to IPC.
--- rod.
 
  


Reply

Tags
programming


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set up an system wide environment variable permanently?? piyush.kansal Fedora 5 12-07-2007 04:04 AM
Environment variable vedanu Programming 1 05-17-2007 07:20 AM
Environment Variable salmanucit Linux - Software 2 07-21-2004 02:27 AM
Help php compile javac or java system environment variable antony_csf Programming 1 06-16-2004 01:12 PM
environment variable mimi Linux - Newbie 1 04-10-2002 08:29 AM


All times are GMT -5. The time now is 05:26 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration