This repository provide a C library for shared memory in the connecktail project in order to know the pid of the different processes.
- clone the repository
- execute the following commands :
make
make installThe headers have been added to the /usr/include/shm-utils repository
In your code, you have just to include the shmutils.h header file :
#include <shm-utils/shmutils.h>Because the functions to get or modify the shared memory need the shared memory id, you have to declare a global variable in your code :
int shmid;Its value will be the result of the init_shared_memory() function.
If you want to use the static library, you have just to specify the path of the lib and its name :
gcc file.c -L path/to/libshm-utils.a -lshm-utils -o fileOn the other hand, if you want to use the dynamic library, specify the name of the lib during the links edition :
gcc file.c -lshm-utils -o filetypedef struct
{
pid_t main_pid;
pid_t websocket_pid;
pid_t device_handler_pid;
} shm_t;- Initialize the shared memory :
int init_shared_memory()- Retrieve the shared memory (readonly):
shm_t *get_shm();- Modify the pid of the main process :
void change_main_pid(int pid)- Modify the pid of the websocket process :
void change_websocket_pid(int pid)- Modify the pid of the device handler process :
void change_device_handler_pid(int pid)- Create and set the shared memory :
void set_init_shm()