2019-10-23 21:39:09 +02:00
|
|
|
#include <cstdlib>
|
2019-11-06 13:07:33 +01:00
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
2019-10-19 17:12:14 +02:00
|
|
|
#include "SharedMemory.h"
|
2019-11-06 13:07:33 +01:00
|
|
|
#include <iostream>
|
|
|
|
#define Max_Memory_Size 8000
|
2019-10-19 17:12:14 +02:00
|
|
|
|
2019-11-06 13:07:33 +01:00
|
|
|
int memoryAccessKey = 12345;
|
|
|
|
int memID;
|
2019-11-04 21:02:27 +01:00
|
|
|
|
2019-11-06 13:23:14 +01:00
|
|
|
void sharedMemoryInit() {
|
|
|
|
if ((memID = shmget(memoryAccessKey, Max_Memory_Size, IPC_CREAT | IPC_EXCL | 0666)) < 0) {
|
|
|
|
std::cerr << "Shared memory with Key: " << memoryAccessKey
|
|
|
|
<< " already exists. Delete by Hand before starting vKFM" << std::endl;
|
2019-11-06 13:07:33 +01:00
|
|
|
exit(0);
|
|
|
|
} else {
|
|
|
|
std::cout << "Shared memory with Key: " << memoryAccessKey << " allocated" << std::endl;
|
|
|
|
}
|
2019-10-27 19:46:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 13:07:33 +01:00
|
|
|
void deleteSharedMemory(int s)
|
|
|
|
{
|
|
|
|
if (shmctl(memID, IPC_RMID, NULL) < 0 )
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to remove shared Memory, maybe not existing: try cmd: ipcs " << std::endl;
|
|
|
|
} else {
|
|
|
|
std::cout << "shared Memory deleted" << std::endl;
|
|
|
|
}
|
|
|
|
exit(0);
|
2019-10-20 20:38:12 +02:00
|
|
|
}
|
|
|
|
|
2019-11-06 13:07:33 +01:00
|
|
|
void deleteSharedMemory(void)
|
|
|
|
{
|
|
|
|
if (shmctl(memID, IPC_RMID, NULL) < 0 )
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to remove shared Memory, maybe not existing: try cmd: ipcs " << std::endl;
|
|
|
|
} else {
|
|
|
|
std::cout << "shared Memory deleted" << std::endl;
|
2019-10-20 20:38:12 +02:00
|
|
|
}
|
2019-11-06 13:07:33 +01:00
|
|
|
exit(0);
|
2019-10-20 20:38:12 +02:00
|
|
|
}
|
|
|
|
|
2019-11-06 13:07:33 +01:00
|
|
|
|