Chances are that - by looking at my
earlier blog entry on batch files -
you think I'm a DOS lamer. Nothing could be further from the truth, because I'm really a UNIX
lamer. (OK, so what
really shaped my thinking even before that was the phrase
"38911 bytes free".
But I digress.)
So I still write little one-off scripts using
bash,
typically in a
Cygwin environment. One of these scripts recently
ran berserk, reporting lots of errors like this one:
./foo.sh: line 42: /usr/bin/find: Resource temporarily unavailable
I couldn't really figure out what resources the shell was talking about. Memory? Certainly
not - the test system had ample memory, and was hardly using any. Files or disk space?
Nope, lots of free disk space everywhere, and noone was fighting over access to
shared files or so. Too many processes? Process Explorer wouldn't think so. Hmmm...
This test script then revealed the truth:
typeset -i limit=2200
# Create a file with 2200 environment variable definitions
rm -f exportlist
typeset -i i=0
while [ $i -lt $limit ]
do
echo "export FOO$i=$i" >>exportlist
let i=i+1
done
# Import the environment definitions
source ./exportlist
# Are we still alive?
env | wc
find . -name exportlist
Run this script and watch it balk miserably about unavailable resources. So it's the
environment which filled up and caused my scripts to fail! And indeed,
the system for which the problem was originally reported uses a
lot of environment
variables for some reason, and this broke my script.
Once I had found out that much, it was easy to google for the right search terms
and learn more:
In
this Cygwin mailing list discussion,
Mike Sieweke explains that we are actually suffering from a Windows limitation here -
apparently, the environment cannot grow larger than 32K. Christopher Faylor,
chief maintainer of Cygwin, even
recommends a workaround,
but I haven't tested that one yet; instead, I helped to clean up the polluted
environment on the affected PC, and henceforth, no
waldsterben anymore on that
system.
32K - this would have filled almost all of those 38911 memory bytes assigned
for BASIC programs on my good ol' 64...
to top