Less than a week after I posted about how I like my new dzen status bar, I discovered an annoying fact about Bash.

If you run the following snippet:

while :; do
  sleep 0.001
done

You will see memory usage growing, but its not some kind of memory leak, because it eventually will stop at some point. I realized its about external command, which is sleep in this case. If you use builtin, e.g.

while :; do
  read -t 0.001
done

The memory usage is fixed from the beginning. Somehow, calling external commands causes such situation. Unfortunately, its nearly impossible for a shell script not to use any external commands.

I was hoping, my status.sh would use some reasonable amount memory after growing, but it reached 100MB+ and still growing. I had no idea when it would stop eating memory, therefore I decided to port the script to C code. And there it is, status.c.

Now, the memory usage is 1,364KB (status.c) + 3,292KB (dzen2).

The C code doesnt do more than the Bash script, in fact, I removed some small stuff. Its basically almost same result but runs faster and efficiently.

Its one-day work and my C skill isnt good, the code is lack of error handling and testing, and many stuff are hard-coded. So, you know what to expect.