accessing external environment lists

accessing external environment lists

Post by Omon Edek » Wed, 30 Apr 2003 00:50:50

Dear All,
I am desperately trying to access the environment variable for a process
given its PID in solaris. I have tried reading from /proc/<PID>/psinfo
into a psinfo_t
struct, and there is a member variable that returns a pointer to an
environment list.However accessing that pointer yields eerie segmentation
faults.I am accessing that pointer as though it were an

char** environ

environment variable array , the normal way :

In general, the `environ' variable is also passed as the third, optional,
parameter to `main()'; that is, the above could have been written:

     #include <stdio.h>

     int fxn(int pid)
        //Process structure from <procfs.h> (solaris)
        struct psinfo_t proc_info;


                Code to acceess psinfo_t from /proc/<PID>/psinfo
                using read()


        char** envp = (char**)proc_info.pr_envp;
         char *p;
         while ((p = *envp++))
                printf("%s\n", p); // >>>This leads to a CRASH segfault
                 return 0;

I am able to access some of
the variables, but I end up with segmentation faults.Does anyone have any
other method to access the environment variable(s) of an 'external'
process ie My process 'A' wants to access the environment list of another
process 'B'.This is for solaris, not Linux.

Omon Edeki

"Conquering Nearly Impossible Challenges is the Most Beautiful Feeling in
the World."


1. portable way to access environment list

Is there a 'portable' means (other than 'system("env")') of getting the
list of environmental variables and their values from within a 'C'

(I don't think main(int argc, char **argv, char **env) is portable...)
(...but I'm not sure.)


2. network capable floppy

3. Use of an external file listing hostnames for access control

4. 3c905b

5. ACL (access control list) howto list them?


7. Setting an environment variable for a process, external of that process.

8. Buggy motherboard?

9. Build vhost list with external script?

10. How to retrieve list of environment variables in C/C++?

11. URGENT HELP -- ARGV list as environment variable

12. environ environment list

13. List of all Environment Variables