Environment Variables – Are 184 Too Many?

environment-variablesprofileqnx

I am trying to find the cause of some OS wonkiness, and am concerned about environment variables.

The software I have been handed puts an incredibly high amount of environment variables into the user's .profile.

When I type set | wc the result is 9571 bytes long! There are 184 entries. To me, this seems inordinately large, but I don't have anything explicit to point at and say "this is wrong because xyz".

I see nothing in the ulimit documentation that speaks about environment variable total size, but am concerned. I'm not worried about overall memory utilization (there's enough to do what I need), but I am worried about overrunning some internal limit and causing odd behavior in the OS (probably not germane to the question I'm asking, but the "odd behavior" is that shared memory queues are not giving me back all the data I put in on the other end. I'm getting around 5% out).

Every single script that starts up, every single shell that is run, and every single binary that runs gets a full, individual copy of the environment variables, and I think 9k is too big. Should this be a worry, or am I concerned over nothing?

I'm running on an embedded x86 QNX 6.4.1 Neutrino system with half a gig of RAM.

Best Answer

When I type set | wc the result is 9571 bytes long!

Assuming you got that number correct, it is in fact quite small, probably because you are using QNX. On a normal desktop system, it is much larger. Here's what I get on fedora 20:

> set | wc --bytes
133195

133 kB. I did not count the entries as many of them are sourced functions (git seems to install a lot of these), but I did skim them over and there doesn't seem to be anything untoward. A few kB at most is from custom stuff by me.

I am worried about overrunning some internal limit and causing odd behavior in the OS

I very much doubt this is possible because a lack of bounds checking there would indicate a very significant bug in the implementation -- preventing someone from just writing a long variable to inject data into memory has to have been a basic concern. Beyond that, as you say, 9kB is nothing memory wise. I would presume lookups on these are done with a hash table, so the number of entries would not impair performance.

Related Question