Skip to contentSkip to conversation

4096 byte limit to /proc/PID/environ ?

DISCUSSION James Pearson 3 participants 4 messages May 24, 2006

lore
Share & tools
lore
#0 lore raw

It appears that /proc/PID/environ only returns the first 4096 bytes of a processes' environment.

Is there any other way via userland to get the whole environment for a process?

Thanks

James Pearson

#1 lore raw
Quoted 9 lines · James Pearson

It appears that /proc/PID/environ only returns the first 4096 bytes of a processes' environment.

Is there any other way via userland to get the whole environment for a process?

Thanks

James Pearson

I think that /proc/PID/environ just returns the environment that existed when the process was created, irrespective of size. You can check this as:

#include <stdio.h>

main()

{
     setenv("FOO=", "1234", 1);
     printf("%d\n", getpid());
     pause();
}

Variable "FOO" will not appear in /proc. It you set the environment in non-standard ways, overwriting the original, you can see it in /proc.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.4 on an i686 machine (5592.89 BogoMips). New book: http://www.AbominableFirebug.com/
_


****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

#2 lore raw
Quoted 28 lines · linux-os (Dick Johnson)
Quoted 9 lines · James Pearson

It appears that /proc/PID/environ only returns the first 4096 bytes of a processes' environment.

Is there any other way via userland to get the whole environment for a process?

Thanks

James Pearson

I think that /proc/PID/environ just returns the environment that existed when the process was created, irrespective of size. You can check this as:

#include <stdio.h>

main()

{
     setenv("FOO=", "1234", 1);
     printf("%d\n", getpid());
     pause();
}
Quoted 3 lines

Variable "FOO" will not appear in /proc. It you set the environment in non-standard ways, overwriting the original, you can see it in /proc.

I'm not worried about that - more the fact that when I do:

% cat /proc/$$/environ | wc -c
4096
% env | wc -c
7329

/proc/PID/environ is truncated ...

James Pearson

#3 lore raw
Followup to:  <[email protected]>
By author:    James Pearson <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 10 lines

I'm not worried about that - more the fact that when I do:

% cat /proc/$$/environ | wc -c
4096
% env | wc -c
7329

/proc/PID/environ is truncated ...

Funny enough, I was looking at this yesterday. I think there is a pretty clean solution for it, I just haven't had a chance to attack it yet.

-hpa