c++ - So, what exactly is the deal with QSharedMemory on application crash? -


when qt application uses qsharedmemory crashes, memory handles left stuck in system. "recommended" way rid of them

if(memory.attach(qsharedmemory::readwrite))     memory.detach(); bool created = memory.create(datasize, qsharedmemory::readwrite); 

in theory above code should work this:

we attach left on piece of sh...ared memory, detach it, detects last living user , gracefully goes down.

except... not happens in lot of cases. see happening, lot, this:

// fails memory.error() =  sharedmemoryerror::notfound memory.attach(qsharedmemory::readwrite); // fails "segment exists" .. wait, what?! (see above) bool created = memory.create(datasize, qsharedmemory::readwrite); 

the working way i've found me work around write pid file on application startup containing pid of running app. next time same app run picks file , does

//qprocess::make sure pid not reused app @ moment //the output of command below should empty ps -p $previouspid -o comm= //qprocess::(runs script, reads output) ipcs -m  -p | grep $user | grep $previouspid | sed "s/  / /g" | cut -f1 -d " " //qprocess::(passes result of previous script clean stuff) ipcrm -m $1 

now, can see problems such approach myself, the thing works

the question is: can explain me deal not not existing memory in first piece of code above , how deal properly?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -