Getting another process' environment

Suppose that I have an environment variable (call it "EVAR") that I set before running a process (call it "myproc"). "myproc" is run multiple times by multiple users and each may set "EVAR" differently. I.E.:

UserA:
export EVAR=v1
myproc

UserB:
export EVAR=v2
myproc

Now "myproc" is running twice, each with different values of "EVAR". Now, let us say that I have another application, "qryproc" who can find all instances of "myproc" that are running. However, for "qryproc" to do its job, it needs to know what "EVAR" looks like for each instance of "myproc" it knows about.

Is this doable? Assume that "qryproc" will be running as root.

Thanks for any ideas....

Your method is flawed imo.
Given that, you could handle this several ways off the top of my head using sockets or strictly sys v ipc. A named pipe seems like a workable solution.

If I 'had' to do it this way I would use signals, a shared memory segment and semaphore set.

I think you can use argv[] for specifying arguments and it can be read by 'ps' and equivalent methods.

If you really need to use ENV then the program can copy suitable information to argv[1] (which must have proper length for that) and the rest is the same as above.

I did not want "qryproc" to have to talk directly to "myproc" (via some IPC method) because that would require me to change every different flavor of "myproc" in our system to be capable of making its data available to "qryproc".

Barring any suggestions how to tap into a non-modified "myproc" and extract its environment, I guess I'll have no choice but to make "myproc" and "qryproc" able to talk to one another.

Edit: also, I have simplified the problem, EVAR is just a single piece of the environment, "qryproc" wants to be capable of seeing "all of it." (I.E. "myproc" uses a bunch of environment variables to configure itself and I need "qryproc" to deterime how each instance "myproc" it knows about is currently configured).