I've got 2 processes (Client and Server) that are communicating through shared memory.
I need to create a 2D Array that is Dynamic (based on parameters). The array is stored in a struct and then written to the shared segment.
I can write the array to the shared memory, but cannot retrieve it from the other process.
Client Code:
struct shared_use_st {
int written_by_you;
int **PID_PRI_array;
};
/* Prepare Dynamic 2D array */
data_store = malloc(/*ROWS*/ 5 * sizeof(int*));
for(i=0;i<5; i++)
data_store[i] = malloc(/*COLS*/ 2 * sizeof(int));
/* Prepare Dynamic 2D array - Shared Memory Seg */
shared_stuff->PID_PRI_array = malloc(/*ROWS*/ 5 * sizeof(int*));
for(i=0;i<5; i++)
shared_stuff->PID_PRI_array[i] = malloc(/*COLS*/ 2 * sizeof(int));
/* Write PID and PRI to data_store array */
data_store[0][0] = pid;
data_store[0][1] = 1;
data_store[1][0] = 12345;
data_store[1][1] = 2;
data_store[2][0] = 12346;
data_store[2][1] = 3;
data_store[3][0] = 12347;
data_store[3][1] = 4;
data_store[4][0] = 12348;
data_store[4][1] = 5;
for(i=0;i<5;i++){
for(x=0;x<=1;x++){
shared_stuff->PID_PRI_array[i][x] = data_store[i][x];
}
}
Server Code:
for(i=0;i<5;i++){
printf("PID: %d, PRI:%d\n", shared_stuff->PID_PRI_array[i][0], shared_stuff->PID_PRI_array[i][1]);
}
I get a "Segmentation Fault" error.
Thanks.