Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cant resolve mac too many files open error

I’m getting too many files open error whenever i try to run source .bashrc

my .basrc file currently contains

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# Auto-complete command from history
# http://lindesk.com/2009/04/customize-terminal-configuration-setting-bash-cli-power-user/
export INPUTRC=~/.inputrc
. "$HOME/.cargo/env"

and i get the following error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/Users/[user]/.bashrc:.:5: too many open files: /Users/[user]/.bashrc
/Users/[user]/.bashrc:.:11: too many open files: /Users/[user]/.cargo/env

I’ve followed the steps in a bunch a guides to no avail. Has anyone come across this issue before and have been able to resolve it? thanks!

What i’ve tried

I’ve checked the limit using launchctl limit maxfiles and it gives me maxfiles 256 unlimited

I’ve also checked the number of processes currently running with lsof -n | awk '{print $1, $2}' | uniq -c | sort -rn | head -n $LINES which gives

689 Arc 2156
292 UserEvent 681
273 corespotl 757
184 Electron 866
174 CoreSpotl 1636
170 Spotlight 895
136 AppleSpel 989
118 Notificat 763
117 bird 747
99 suggestd 789
97 Terminal 862
97 Code\x20H 1214
90 loginwind 181
90 Code\x20H 1235
85 Finder 873
80 accountsd 686
76 java 1374
76 java 1360
75 Arc\x20He 2171
73 TextEdit 2307
69 ControlCe 782
67 identitys 711
66 com.apple 2310
63 Maccy 1095

I’ve tried changing the limit for the files using sudo launchctl limit maxfiles 1024 4096

instead of increasing the number of files this makes everything stop working and causes my mac to restart.

>Solution :

You have bashrc sourcing itself, which sources itself, which sources itself… since this is .bashrc, it gets sourced automatically when a bash shell is opened.

Remove this block and it should work:

if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

Basically, the above if statement is checking for the existence of a file called .bashrc in your home dir. But since this block is in that file, it is self referencing and continues to call itself recursively until it hits the defined limits as you found.

If you had another file you wanted to also source when bash starts, say, that had other code or aliases in it, you could use this block to source that file. You just don’t want to source the same file that this block exists in from itself, or you get the self-referencing recursion you discovered.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading