2019-10-23 21:39:09 +02:00
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstdio>
|
2019-10-19 17:12:14 +02:00
|
|
|
|
#include "SharedMemory.h"
|
|
|
|
|
|
2019-10-19 19:18:34 +02:00
|
|
|
|
//Shared-Memory-Segment erstellen oder öffnen – shmget()
|
2019-10-23 11:53:07 +02:00
|
|
|
|
void shared_memory_init(){
|
|
|
|
|
memory_id = shmget(IPC_PRIVATE, SHMMAXSIZE, IPC_CREAT | IPC_EXCL);
|
2019-10-31 23:31:28 +01:00
|
|
|
|
if(memory_id<0){
|
|
|
|
|
perror("Fehler bei der Erstellung des gemeinsamen Speicher");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
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);
|
|
|
|
|
}
|