39.8 A Big Environment Can Slow You DownPart of starting a new child process (starting a program, for instance) is making a copy of the environment from the parent process. Some computers, especially busy ones, aren't very fast at making new processes. (In the early 1980s, I worked on a VAX 11/750 running 4.1 BSD; the load average got above 40. Sometimes, after a command finished, it could take 10 or 20 seconds just to get the next shell prompt. Sheesh!) Filling up your environment with lots of variables (the csh command setenv or the sh command export ) can be handy. But it can slow you down - especially in shell scripts that run loops, starting lots of subprocesses. I did a test on our 386-based computer running Interactive UNIX System V/386 Release 3.2 late one night when I was the only user logged on. First, I cleaned out my environment to around 300 characters. Then I did:
That started the short /bin/true shell script 50 times. I added up the system times (from the second column) and got 6.9 CPU seconds. Then I used a C shell while loop to quickly add a bunch of huge environment variables named FOO1 , FOO2 , and so on, like this:
and ran A thorough test? Nope. But if you have a big environment on a slow computer, you might run a test like this to see whether cleaning it out - replacing environment variables with shell variables, for instance - can make your subprocesses start faster. Article 38.7 explains the problem a big environment can cause for ps . Article 2.9 shows how to start C shells more quickly. - |
|