I am running Raspbian on a Raspberry Pi which is located in a remote location. I use Putty to connect to it via SSH.

I can connect fine but when I try to run any command I get the following:

-bash: fork: Cannot allocate memory

I've looked at many answers online but they all assume I am physically collocated with the Raspberry, which is not the case for me. I can't simply pull the plug to restart it or use the GUI.

I need to fix this issue to have it operational again. Doing a restart using sudo reboot would be the most straightforward option but that doesn't work either. How can I restart the Pi remotely or free up enough memory to do a sudo reboot?

Note that the only command I managed to find that works is ulimit -a. I've tried sudo, reboot, shutdown, top, ps, sh but none work.


After about an hour, some memory freed up somehow and I was able to restart it. I pinpointed the memory leak to be caused by a python script set to execute daily that was hanging every time. Moral of the story: always set a timeout on all scripts and kill them after the period has passed to prevent memory leak issues!

I am still looking for a way to do it as waiting is not really a guaranteed solution, nor is it available to everyone.

  • The core notion is to find out where the memory has gone. Something in your application/environment is leaking resources (memory, file descriptors, processes etc etc). What you need to do is solve that problem. If you are leaking resources, then any ability to login will only be temporary until more resources are again used up. I get the feeling that machine is in a state that you may not be able to remotely login to check the status but will instead have to physically reboot it. – Kolban May 22 '16 at 15:31
  • 1
    I plan to investigate the leak, but first I need to be able to use the device, for which I need to do a reboot, hence this question. – Vlad Schnakovszki May 22 '16 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.