I want to read an environment variable value of a running process from /proc
file system.
I could not find /proc/<pid>/environ
file on QNX.
I know how we can read it from getenv API but I want to read it from /proc/<pid>
.
To the best of my knowledge there's no easy-to-use API on QNX for accessing another program's environment programmatically.
If your application permits, the easiest solution is to use QNX's pidin
-- run pidin -p <pid> environment
to dump the environment to the standard output.
If you cannot spawn additional processes, what I believe pidin
is doing internally is something like:
DCMD_PROC_INFO
to retrive the virtual address of the initial stack of the target process;/proc/<pid>/as
, seek to the inital stack address, and parse through it:
argc
argv
, so skip past that many char*s, plus one