Same process has different environmental variables in /proc/pid/environ when seen from different sessions. Why?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I was checking environmental variables of bash process of an xterm that was started inside vnc session.



If I check the environmental variables from the bash session itself by running env or cat /proc/pid/environ | strings, it shows all the environmental variables that would generally be set when we do su or ssh i.e., from /etc/profile and .bashrc. But when I do cat /proc/pid/environ | strings from a putty session, it shows completely different variables.



Putting aside why only those specific variables are set, I want to know why environ of same process has different results when checked from different sessions like a double slit experiment. I understand that proc is not real filesystem. But what exactly is happening when I'm querying it and so is proc not realiable way to check remote process environment?



I wrote the question from my phone. So, I don't have any sample output to show. But, I hope you get my question.







share|improve this question
















  • 1




    /proc/pid/environ is a pretty straightforward dump of a piece of memory. It's the same piece of memory no matter what process asks the kernel to dump it. Given your vague description, my impression is that you're looking at different processes (different PIDs, or same PID on different machines, or same PID in different PID namespaces).
    – Gilles
    Jan 3 at 21:06














up vote
1
down vote

favorite












I was checking environmental variables of bash process of an xterm that was started inside vnc session.



If I check the environmental variables from the bash session itself by running env or cat /proc/pid/environ | strings, it shows all the environmental variables that would generally be set when we do su or ssh i.e., from /etc/profile and .bashrc. But when I do cat /proc/pid/environ | strings from a putty session, it shows completely different variables.



Putting aside why only those specific variables are set, I want to know why environ of same process has different results when checked from different sessions like a double slit experiment. I understand that proc is not real filesystem. But what exactly is happening when I'm querying it and so is proc not realiable way to check remote process environment?



I wrote the question from my phone. So, I don't have any sample output to show. But, I hope you get my question.







share|improve this question
















  • 1




    /proc/pid/environ is a pretty straightforward dump of a piece of memory. It's the same piece of memory no matter what process asks the kernel to dump it. Given your vague description, my impression is that you're looking at different processes (different PIDs, or same PID on different machines, or same PID in different PID namespaces).
    – Gilles
    Jan 3 at 21:06












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I was checking environmental variables of bash process of an xterm that was started inside vnc session.



If I check the environmental variables from the bash session itself by running env or cat /proc/pid/environ | strings, it shows all the environmental variables that would generally be set when we do su or ssh i.e., from /etc/profile and .bashrc. But when I do cat /proc/pid/environ | strings from a putty session, it shows completely different variables.



Putting aside why only those specific variables are set, I want to know why environ of same process has different results when checked from different sessions like a double slit experiment. I understand that proc is not real filesystem. But what exactly is happening when I'm querying it and so is proc not realiable way to check remote process environment?



I wrote the question from my phone. So, I don't have any sample output to show. But, I hope you get my question.







share|improve this question












I was checking environmental variables of bash process of an xterm that was started inside vnc session.



If I check the environmental variables from the bash session itself by running env or cat /proc/pid/environ | strings, it shows all the environmental variables that would generally be set when we do su or ssh i.e., from /etc/profile and .bashrc. But when I do cat /proc/pid/environ | strings from a putty session, it shows completely different variables.



Putting aside why only those specific variables are set, I want to know why environ of same process has different results when checked from different sessions like a double slit experiment. I understand that proc is not real filesystem. But what exactly is happening when I'm querying it and so is proc not realiable way to check remote process environment?



I wrote the question from my phone. So, I don't have any sample output to show. But, I hope you get my question.









share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 17:18









Jeevan Patnaik

1952518




1952518







  • 1




    /proc/pid/environ is a pretty straightforward dump of a piece of memory. It's the same piece of memory no matter what process asks the kernel to dump it. Given your vague description, my impression is that you're looking at different processes (different PIDs, or same PID on different machines, or same PID in different PID namespaces).
    – Gilles
    Jan 3 at 21:06












  • 1




    /proc/pid/environ is a pretty straightforward dump of a piece of memory. It's the same piece of memory no matter what process asks the kernel to dump it. Given your vague description, my impression is that you're looking at different processes (different PIDs, or same PID on different machines, or same PID in different PID namespaces).
    – Gilles
    Jan 3 at 21:06







1




1




/proc/pid/environ is a pretty straightforward dump of a piece of memory. It's the same piece of memory no matter what process asks the kernel to dump it. Given your vague description, my impression is that you're looking at different processes (different PIDs, or same PID on different machines, or same PID in different PID namespaces).
– Gilles
Jan 3 at 21:06




/proc/pid/environ is a pretty straightforward dump of a piece of memory. It's the same piece of memory no matter what process asks the kernel to dump it. Given your vague description, my impression is that you're looking at different processes (different PIDs, or same PID on different machines, or same PID in different PID namespaces).
– Gilles
Jan 3 at 21:06










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Here is what I did for a test:



$export test=one
$vim test1


pid = 1200, Stopped the process with CTRL-Z



$cat /proc/1200/environ | strings
test=one


Now for second process



$test=two
$vim test2


pid = 1201, Stopped the process with CTRL-Z



$cat /proc/1201/environ | strings
test=two


The user might have changed the environment properties before running the program.






share|improve this answer






















  • I was testing both the sessions in parallel, it shows different environment variables at a time for same process
    – Jeevan Patnaik
    Jan 3 at 18:19






  • 1




    Does the program modify the environment variables?
    – randominstanceOfLivingThing
    Jan 3 at 19:27










  • I forgot to do followup on this question. Yes, I had later realized that /proc/pid/environ doesn't actually display realtime environmental variables. But it only shows the environmental variable that were there when the process is started. So, it appears that the environmental variable was changed after the process is started. Thank you!
    – Jeevan Patnaik
    Mar 9 at 18:51











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f414588%2fsame-process-has-different-environmental-variables-in-proc-pid-environ-when-see%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Here is what I did for a test:



$export test=one
$vim test1


pid = 1200, Stopped the process with CTRL-Z



$cat /proc/1200/environ | strings
test=one


Now for second process



$test=two
$vim test2


pid = 1201, Stopped the process with CTRL-Z



$cat /proc/1201/environ | strings
test=two


The user might have changed the environment properties before running the program.






share|improve this answer






















  • I was testing both the sessions in parallel, it shows different environment variables at a time for same process
    – Jeevan Patnaik
    Jan 3 at 18:19






  • 1




    Does the program modify the environment variables?
    – randominstanceOfLivingThing
    Jan 3 at 19:27










  • I forgot to do followup on this question. Yes, I had later realized that /proc/pid/environ doesn't actually display realtime environmental variables. But it only shows the environmental variable that were there when the process is started. So, it appears that the environmental variable was changed after the process is started. Thank you!
    – Jeevan Patnaik
    Mar 9 at 18:51















up vote
1
down vote



accepted










Here is what I did for a test:



$export test=one
$vim test1


pid = 1200, Stopped the process with CTRL-Z



$cat /proc/1200/environ | strings
test=one


Now for second process



$test=two
$vim test2


pid = 1201, Stopped the process with CTRL-Z



$cat /proc/1201/environ | strings
test=two


The user might have changed the environment properties before running the program.






share|improve this answer






















  • I was testing both the sessions in parallel, it shows different environment variables at a time for same process
    – Jeevan Patnaik
    Jan 3 at 18:19






  • 1




    Does the program modify the environment variables?
    – randominstanceOfLivingThing
    Jan 3 at 19:27










  • I forgot to do followup on this question. Yes, I had later realized that /proc/pid/environ doesn't actually display realtime environmental variables. But it only shows the environmental variable that were there when the process is started. So, it appears that the environmental variable was changed after the process is started. Thank you!
    – Jeevan Patnaik
    Mar 9 at 18:51













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Here is what I did for a test:



$export test=one
$vim test1


pid = 1200, Stopped the process with CTRL-Z



$cat /proc/1200/environ | strings
test=one


Now for second process



$test=two
$vim test2


pid = 1201, Stopped the process with CTRL-Z



$cat /proc/1201/environ | strings
test=two


The user might have changed the environment properties before running the program.






share|improve this answer














Here is what I did for a test:



$export test=one
$vim test1


pid = 1200, Stopped the process with CTRL-Z



$cat /proc/1200/environ | strings
test=one


Now for second process



$test=two
$vim test2


pid = 1201, Stopped the process with CTRL-Z



$cat /proc/1201/environ | strings
test=two


The user might have changed the environment properties before running the program.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 4 at 5:21









Andy Dalton

4,7841520




4,7841520










answered Jan 3 at 18:00









randominstanceOfLivingThing

21816




21816











  • I was testing both the sessions in parallel, it shows different environment variables at a time for same process
    – Jeevan Patnaik
    Jan 3 at 18:19






  • 1




    Does the program modify the environment variables?
    – randominstanceOfLivingThing
    Jan 3 at 19:27










  • I forgot to do followup on this question. Yes, I had later realized that /proc/pid/environ doesn't actually display realtime environmental variables. But it only shows the environmental variable that were there when the process is started. So, it appears that the environmental variable was changed after the process is started. Thank you!
    – Jeevan Patnaik
    Mar 9 at 18:51

















  • I was testing both the sessions in parallel, it shows different environment variables at a time for same process
    – Jeevan Patnaik
    Jan 3 at 18:19






  • 1




    Does the program modify the environment variables?
    – randominstanceOfLivingThing
    Jan 3 at 19:27










  • I forgot to do followup on this question. Yes, I had later realized that /proc/pid/environ doesn't actually display realtime environmental variables. But it only shows the environmental variable that were there when the process is started. So, it appears that the environmental variable was changed after the process is started. Thank you!
    – Jeevan Patnaik
    Mar 9 at 18:51
















I was testing both the sessions in parallel, it shows different environment variables at a time for same process
– Jeevan Patnaik
Jan 3 at 18:19




I was testing both the sessions in parallel, it shows different environment variables at a time for same process
– Jeevan Patnaik
Jan 3 at 18:19




1




1




Does the program modify the environment variables?
– randominstanceOfLivingThing
Jan 3 at 19:27




Does the program modify the environment variables?
– randominstanceOfLivingThing
Jan 3 at 19:27












I forgot to do followup on this question. Yes, I had later realized that /proc/pid/environ doesn't actually display realtime environmental variables. But it only shows the environmental variable that were there when the process is started. So, it appears that the environmental variable was changed after the process is started. Thank you!
– Jeevan Patnaik
Mar 9 at 18:51





I forgot to do followup on this question. Yes, I had later realized that /proc/pid/environ doesn't actually display realtime environmental variables. But it only shows the environmental variable that were there when the process is started. So, it appears that the environmental variable was changed after the process is started. Thank you!
– Jeevan Patnaik
Mar 9 at 18:51













 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f414588%2fsame-process-has-different-environmental-variables-in-proc-pid-environ-when-see%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay