Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZSH keeps breaking with `zsh: fork failed:`

In the past few weeks (possibly since I upgraded to Sierra) I keep getting this weird issue in iTerm2 using ZSH.

Basically, at intermittent points during my regular workflow, commands will stop working properly with the error:

_run-with-bundler:5: fork failed: resource temporarily unavailable
zsh: fork failed: resource temporarily unavailable

Does anybody know why this is happening, and how I can fix it?

like image 353
bodacious Avatar asked Dec 16 '16 15:12

bodacious


1 Answers

This error might reflect a memory leak in your workflow. I had the issue with an automated script lately, and found that memory usage increased to around 100% before my program failed with this message.

You can generally check for memory leakage by running the Activity Monitor application on your Mac OS and navigating to the memory tab. There's also many ways to monitor memory from a zsh terminal, e.g. you can print out the number of processes with $ ps -eLf | wc -l, or check free memory with free -m.

If it is a memory issue, the best fix would be to rewrite your workflow to be more memory efficient. Another fix could be to increase your computer's limit on the processes it can run, e.g. by adding the following to your etc/profile file;

if [ $USER = "oracle" ]; then
    if [ $SHELL = "/bin/ksh" ]; then
        ulimit -p 16384
        ulimit -n 65536
    else
        ulimit -u 16384 -n 65536
    fi
fi

References:

  • for resolving the issue by increasing the number of permitted processes; https://access.redhat.com/solutions/22105
  • More ways to monitor memory consumption; https://www.linux.com/tutorials/5-commands-checking-memory-usage-linux/
like image 148
Mac Strelioff Avatar answered Oct 06 '22 01:10

Mac Strelioff