SSH and -bash: fork: Cannot allocate memory VPS Ubuntu SSH and -bash: fork: Cannot allocate memory VPS Ubuntu nginx nginx

SSH and -bash: fork: Cannot allocate memory VPS Ubuntu


Seems you have run out of memory. Many VPS servers are setup with no swap, so when you run out of memory, it will kill things off in a seemingly random manner.

The easiest way to fix it is to get more memory provisioned to your VPS, likely costing more money. The next best way (other than running less stuff and memory optimizing everything running) would be to add a swap partition or swap file.

For a 1GB swap file (as root):

dd if=/dev/zero of=/swapfile bs=1M count=1024mkswap /swapfileswapon  /swapfile

Be sure to add it to /etc/fstab too as:

/swapfile none swap defaults 0 0

That will make it come back after reboot.


To get out of this condition without rebooting, you can trigger the OOM killer manually as follows:

echo 1 > /proc/sys/kernel/sysrqecho f > /proc/sysrq-triggerecho 0 > /proc/sys/kernel/sysrq

Having done so you can inspect dmesg to find the process responsible for taking all your memory.