+ send an receive signals

This commit is contained in:
Julian Hinxlage 2019-11-06 12:47:34 +01:00
parent 9ce7b06c83
commit daa65080e6
2 changed files with 24 additions and 1 deletions

View File

@ -1,11 +1,13 @@
#include "internal.h" #include "internal.h"
#include <sys/shm.h> #include <sys/shm.h>
#include <csignal>
Impl impl; Impl impl;
void *getSharedMemory(){ void *getSharedMemory(){
impl.sharedMemorySize = 8000; impl.sharedMemorySize = 8000;
auto id = shmget(impl.sharedMemoryKey, impl.sharedMemorySize, 0644 | IPC_CREAT); auto id = shmget(impl.sharedMemoryKey, impl.sharedMemorySize, 0644u | IPC_CREAT);
if(id == -1){ if(id == -1){
//error //error
impl.sharedMemorySize = 0; impl.sharedMemorySize = 0;
@ -25,3 +27,11 @@ void *getSharedMemory(){
int getSharedMemorySize(){ int getSharedMemorySize(){
return impl.sharedMemorySize; return impl.sharedMemorySize;
} }
void sendSignal(pid_t pid, int signalNumber) {
kill(pid, signalNumber);
}
void onSignal(int signalNumber, void(*callback)(int)) {
signal(signalNumber, callback);
}

View File

@ -54,6 +54,19 @@ void *getSharedMemory();
int getSharedMemorySize(); int getSharedMemorySize();
/**
* send a signal to a process
* @param pid of the process to which the signal is send
* @param signalNumber
*/
void sendSignal(pid_t pid, int signalNumber);
/**
* calls the callback if a signal is received
* @param signalNumber
*/
void onSignal(int signalNumber, void(*callback)(int));
/** /**
* set layout version. * set layout version.
* @param newValue new layout version number. * @param newValue new layout version number.