process shared memory not sharing (c, linux) -


i need make shared memory process communicate. i'm doing this:

int **matriz_result; int segment_id; segment_id = shmget(ipc_private, (sizeof(int) * linhas_mat1 * colunas_mat2) , s_irusr | s_iwusr); matriz_result = (int **) shmat(segment_id, null, 0); 

after use fork make more processes. tested , each process writing in matriz_resul, each 1 has own area. if print what's on area, each process print different. memory not sharing. every example have found on internet this. knows i'm doing wrong?

try

segment_id = mmap(null,(sizeof(int) * linhas_mat1 * colunas_mat2),prot_write | prot_read, map_anonymous | map_shared,-1,0 ); 

Comments