2

In bash, .bashrc (and various other scripts) can load into memory at shell startup. These can be 10 lines long, but can be hundreds (if not thousands) of lines long. Each export will consume a tiny amount of memory, and each function and each alias also a little resources to be held in memory. Another consideration is that we can't just look at the size of the .bashrc and other scripts as they could have lots of comments which consume no memory.

I would like to remove all startup scripts, start the system, wait a few minutes for things to settle down and then take some kind of baseline, then put the startup scripts back in place, restart the system and perform the same exercise to try and get some kind of resource / performance diff.

Can you suggest what tools might help to determine this? I have a relatively large set of startup scripts, about 15k with many functions and aliases defined, so I'm really curious what impact (if any, as a modern system with 16 GB of memory and a fast modern Core i5, the effect could be negligible) this has upon the system in terms of consumed resources? Even if the impact of my startup scripts is low, I would still love to be able to take a baseline and then a later 'load test' to get some assessment of how systems handle running a given set of applications.

1 Answer 1

4

The impact of your startup scripts and the resulting setup will mostly affect interactive shells; to determine the resulting resource consumption, you don’t need to go to huge lengths. Open a terminal window, so that your default shell starts with its default setup, then start a shell without loading the startup scripts, and from that shell, run ps -F:

$ bash --norc
$ ps -F
UID          PID    PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
steve    3922819 3921628  0  2307  4812   7 20:49 pts/14   00:00:00 bash
steve    3922883 3922819  0  2276  4688   5 20:49 pts/14   00:00:00 bash --norc
steve    3922884 3922883  0  2892  4244   0 20:49 pts/14   00:00:00 ps -F

Looking at the RSS column shows that my bash setup (which is rather minimal) uses 124KiB more than a no-frills bash.

My Zsh setup is more complex:

$ zsh -f
$ ps -F
UID          PID    PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
steve    3921244   18008  0  3341  8296   2 20:43 pts/14   00:00:00 zsh
steve    3921628 3921244  0  2829  5856   5 20:44 pts/14   00:00:00 zsh -f
steve    3923250 3922883  0  2892  4132   7 20:51 pts/14   00:00:00 ps -F

The difference there is larger, 2440KiB.

Non-interactive shells don’t load the same startup scripts, and they don’t survive long anyway — if you run ps -FC sh, ps -FC bash etc. you should see that there aren’t many (if any at all).

What you load in your environment can have a bigger impact; to get some idea of that, look at the real size of /proc/.../environ:

$ sudo wc -c /proc/*/environ | tail -n 1
758799 total

That’s 741KiB in total, for nearly a thousand running processes.

1
  • This is great information, thanks for these details. It's nice to know that the ~2 MB that my profile is consuming (from the 16 GB memory in my system) is not really an issue. 👍
    – YorSubs
    Oct 4, 2021 at 15:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .