#include <QCoreApplication>#include <QDebug>#include <QSharedMemory>#include <sys/shm.h>#include <errno.h>int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); qDebug() << "Fall infinite, my PID=" << getpid(); QSharedMemory mem; mem.setNativeKey("4589"); qDebug() << "Ok, start, my nativeKey=" << mem.nativeKey() << " key=" << mem.key(); if (!mem.create(7777)) qDebug() << "Create fail:" << mem.errorString(); else qDebug() << "Memory created successfully"; if (mem.attach()) qDebug() << "Attached succesfully"; else qDebug() << "Attach fail:" << mem.errorString(); qDebug() << "_______________________________"; getchar(); return 0;}
C++ (Qt)key = ftok( "4589", 'Q' );