I am running a python program that, for some reason, goes crazy once in a while. I am then forced to kill the program but the RAM and Swap used by the program is not released. This causes the hanging issue during shutdown as has already been reported by other users.

The solution to the hanging issue is to clear the Swap prior to shutdown. The only way I have seen online to clear Swap is through the use of swapoff/swapon. However, use of swapoff requires enough RAM to move everything over (even if the data is no longer in use).

The issue is that the program sometimes also fills the RAM. Thus, the system will refuse to execute swapoff. Is there some way to clear Swap without requiring RAM or am I just going to have to cut power to my computer every time this happens? Alternatively, is there a way to clear RAM so that there is enough space to run swapoff? Or perhaps there is a way to find the memory claimed by the killed program and have Ubuntu clear just that?

  • RAM not released after the app killed? It is either a serious kernel bug, or there's another process owning the RAM, or the app still running (most likely, because SIGTERM is a kind ask for app to terminate, to allow it to close files, sockets, etc). First, try the next killing with SIGKILL, e.g. killall -SIGKILL myapp. It's a bad idea in general, but definitely not worse of stopping the system. If didn't help, then look at ps aux --sort -rss | head -n15 for the most RAM demanding app, it's probably there. Just a note: PSS is the right way to measure RAM, but for our needs RSS is fine.
    – Hi-Angel
    May 28, 2016 at 21:22
  • Oh, and by the way, you may configure OOM killer to kill the most expensive task (by default it kills whatever process is in hand), and use Alt + SysRq + fto manually invoke OOM killer. You, probably, need to enable magic sysrq first, it is by default limited for security reasons.
    – Hi-Angel
    May 28, 2016 at 21:28
  • Thanks. I'll give it a try next time the program gives me trouble. May 29, 2016 at 3:46


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.