Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define LINHAS 3
- #define COLUNAS 3
- #define PULAR_LINHA printf("n")
- int main(int argc, char *argv[])
- {
- int linha, coluna; //indices
- int pid, id;
- int matriz1[][COLUNAS] = { {1,2,3}, {4,5,6}, {7,8,9} };
- int matriz2[][COLUNAS] = { {3,5,3}, {4,5,6}, {7,8,9} };
- int segmento, status;
- segmento = shmget(IPC_PRIVATE, sizeof(int)*18, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
- int *matrizSolucao = (int*)shmat(segmento, NULL, 0);
- id = fork();
- if (id == 0) // Processo filho
- {
- for(linha = 0; linha < LINHAS; linha++)
- {
- for(coluna = 0; coluna < COLUNAS; coluna++)
- printf("%dt", *matrizSolucao);
- printf("n");
- }
- }
- else // Processo pai
- {
- pid = wait(&status);
- for(linha = 0; linha < LINHAS; linha++)
- {
- for(coluna = 0; coluna < COLUNAS; coluna++)
- *matrizSolucao = matriz1[linha][coluna] + matriz2[linha][coluna];
- }
- }
- //Libera a mmoria compartilhada do processo
- shmdt(matrizSolucao);
- //Libera a memoria compartilhada
- shmctl(segmento, IPC_RMID, 0);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement