+ send an receive signals
This commit is contained in:
parent
9ce7b06c83
commit
daa65080e6
|
@ -1,11 +1,13 @@
|
|||
#include "internal.h"
|
||||
#include <sys/shm.h>
|
||||
#include <csignal>
|
||||
|
||||
Impl impl;
|
||||
|
||||
void *getSharedMemory(){
|
||||
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){
|
||||
//error
|
||||
impl.sharedMemorySize = 0;
|
||||
|
@ -25,3 +27,11 @@ void *getSharedMemory(){
|
|||
int getSharedMemorySize(){
|
||||
return impl.sharedMemorySize;
|
||||
}
|
||||
|
||||
void sendSignal(pid_t pid, int signalNumber) {
|
||||
kill(pid, signalNumber);
|
||||
}
|
||||
|
||||
void onSignal(int signalNumber, void(*callback)(int)) {
|
||||
signal(signalNumber, callback);
|
||||
}
|
||||
|
|
|
@ -54,6 +54,19 @@ void *getSharedMemory();
|
|||
|
||||
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.
|
||||
* @param newValue new layout version number.
|
||||
|
|
Loading…
Reference in New Issue