2019-10-23 21:39:09 +02:00
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstdio>
|
2019-10-19 17:12:14 +02:00
|
|
|
|
#include "SharedMemory.h"
|
|
|
|
|
|
2019-11-04 21:02:27 +01:00
|
|
|
|
|
2019-10-19 19:18:34 +02:00
|
|
|
|
//Shared-Memory-Segment erstellen oder öffnen – shmget()
|
2019-11-04 21:02:27 +01:00
|
|
|
|
int shared_memory_init(key_t key){
|
|
|
|
|
|
|
|
|
|
memory_id = shmget(key, SHMMAXSIZE, IPC_CREAT | 0666);
|
|
|
|
|
if(shmid == -1){
|
|
|
|
|
key++;
|
|
|
|
|
shmfnk(key);
|
|
|
|
|
return memory_id;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2019-10-19 17:12:14 +02:00
|
|
|
|
}
|
2019-10-19 19:18:34 +02:00
|
|
|
|
|
2019-10-27 19:46:00 +01:00
|
|
|
|
//Shared-Memory-Segment id weiterreichen
|
|
|
|
|
int get_shared_memory_id(){
|
|
|
|
|
return memory_id;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 20:38:12 +02:00
|
|
|
|
//Ein Shared-Memory-Segment abfragen, ändern oder löschen – shmctl()
|
2019-10-23 11:53:07 +02:00
|
|
|
|
void delet_shared_memory(){
|
2019-10-23 21:39:09 +02:00
|
|
|
|
memory_id = shmctl(memory_id, IPC_RMID, 0);
|
2019-10-20 20:38:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Shared-Memory-Segment an einen Prozess anbinden (attach) – shmat()
|
2019-10-23 21:39:09 +02:00
|
|
|
|
void attach_process(void *myProcess){
|
|
|
|
|
if(( myProcess = shmat( memory_id, (char *)0, 0 )) < (char *)0 ){
|
2019-10-20 20:38:12 +02:00
|
|
|
|
perror("Fehler beim Ankoppeln des gemeinsamen Speicher Segments");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Ein Shared-Memory-Segment loslösen – shmdt()
|
2019-10-23 11:53:07 +02:00
|
|
|
|
void release_memory(){
|
2019-10-20 20:38:12 +02:00
|
|
|
|
int shmdt(void *myProcess);
|
|
|
|
|
}
|