Our couple of users have approached us about getting this error “bash: fork cannot allocate memory” when executing commands in the terminal. Due to this, they can’t able to execute any commands.
The error looks like the given example;
user-Mac-Pro:~ user$ ls -bash: fork: Cannot allocate memory
When getting this error first you have to check the free memory available in the server using the given command;
free -m or free -g
This error causes because of insufficient memory in your machine.
How to Find the Cause of the Issue:
The insufficient memory issue happens due to several reasons but basically, it occurs due to something is eating up all of your memory and not leaving any memory space for even basic command usage.
In order to check which process is taking more memory, you can use the top command.
top or htop
- From the above output of top command you can verify which process is taking more memory. Then you remove/kill faulty process.
Note: If a system process using more memory then don’t kill that process. You have to investigate the process which is using more memory and deal with the process to reduce memory usage.
- Changing the configuration for that program/process, so that it doesn’t eat up all of your memory.
- If there is not available memory then you need to add a swap memory, then it will allocates more memory if you are running out of memory.
- Whenever you install and configure a program/process you should set it up properly otherwise it will use unwanted amount of extra memory or you can optimize your current processes memory.
- Whenever you add a package or anything new you should check it’s memory usage by “top” or “htop” command. If you want any unwanted process there using more memory, then you can kill or remove that processes.
- If you notice any process that is auto-starting (besides the system processes), you should check it and remove it from auto-starting. You should confirm that the process is not be essential procedures or system functions etc. otherwise it will affect your system performance.
You should always monitor your system every time because most of us just find a solution without finding the exact cause of the issue. It will lead to another issue again.
An efficiently working server is the base for every business. Under our server management, we are providing 24/7 monitoring service for our clients.