Fixing “shmget() failed: No space left on device”

I had this happen when someone ran a script to kill x11vnc every so often, using kill -9 (don’t ask).

Killing x11vnc with SIGTERM (15) allows it to clean up its shared memory segments. SIGKILL (9) will not.

Googling around, I found a script over here (backup copy here).

The problem with that was that it’s aimed at being run as the user, and it only supports usernames up to 10 characters, because of how “ipcs -m” prints its entries on Linux.

I wanted a solution that supported any length of username, and that could be run periodically, by root, as a cronjob to clean up after silly users, and that would also give me a report when it cleaned something, so I could see who was causing this.

The result was this script. It only supports Linux, and thus is a bit less portable than the one at, but it does the job, even with long usernames, and generates such nice reports:

Removed SHM Segments:
|   OWNER    |   COUNT    |
| bolt       |         42 |

Total: 42


Updated script, automatically synced with the one I’m actually using available here.


  • Sepp says:

    Great solution!
    Nicely written!
    Does exactly what I needed!

    • bolt says:

      If you want to run the script I wrote, I strongly suggest you use the updated version I just added to the bottom of the post. The other one has some problems, like calling the “printusage” function which doesn’t exist in that script. If you had left your email address, I could have poked you about it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *