Sign in

Linux Shared Memory Crash

Follow

This article specifically addresses a Linux crash bug that causes the software to crash on launch, usually until the system is restarted.

Error message in log file: "Error: Unable to create shared memory to hold instance number, Qt error code: 1, Qt error string: QSharedMemoryPrivate::initKey: unable to set key on lock"

Background

The application uses a shared memory segment to manage specific single instance resources - mainly the protocol search database file.

Every time the application launches, it either attaches to an existing shared memory segment, or creates a new one. When the last instance of the software exits, the shared memory segment is removed.

If the application crashes, the shared memory segment is not removed - however, this is not usually a problem.

This bug only occurs when the software is launched multiple times from different user accounts, usually from the current user and the superuser account, like so:

  • ./Logic
  • sudo ./Logic

When the software is run as the superuser and a shared memory segment is created, that shared memory segment will belong to the superuser. Other instances of the software run as the normal user will fail to attach and crash on launch.

Usually this can be solved simply by closing all open instances of the software that were launched with sudo.

However, if the software launched with sudo crashes, the shared memory segment might not get released. Any instance of the software launched without root permissions will crash on launch with the above error.

Solution

The simplest way to solve this is to restart the computer. Shared memory segments are not persisted between restarts.

Alternatively, the problem can be solved by manually removing the shared memory segment and associated semaphore.

  1. list all shared memory segments and semaphores. sudo ipcs

  2. locate the shared memory segment The shared memory segment used by the Logic software will be owned by root and contain 4 bytes. ``` ------ Shared Memory Segments


trello ID: 5978f9477974fe271475603d
Have more questions? Submit a request

Comments

Powered by Zendesk