Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #define LINHAS 3
  2. #define COLUNAS 3
  3. #define PULAR_LINHA printf("n")
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.  
  8. int linha, coluna; //indices
  9. int pid, id;
  10. int matriz1[][COLUNAS] = { {1,2,3}, {4,5,6}, {7,8,9} };
  11. int matriz2[][COLUNAS] = { {3,5,3}, {4,5,6}, {7,8,9} };
  12. int segmento, status;
  13. segmento = shmget(IPC_PRIVATE, sizeof(int)*18, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  14. int *matrizSolucao = (int*)shmat(segmento, NULL, 0);
  15. id = fork();
  16.  
  17. if (id == 0) // Processo filho
  18. {
  19. for(linha = 0; linha < LINHAS; linha++)
  20. {
  21. for(coluna = 0; coluna < COLUNAS; coluna++)
  22. printf("%dt", *matrizSolucao);
  23. printf("n");
  24. }
  25. }
  26. else // Processo pai
  27. {
  28. pid = wait(&status);
  29. for(linha = 0; linha < LINHAS; linha++)
  30. {
  31. for(coluna = 0; coluna < COLUNAS; coluna++)
  32. *matrizSolucao = matriz1[linha][coluna] + matriz2[linha][coluna];
  33. }
  34. }
  35. //Libera a mmoria compartilhada do processo
  36. shmdt(matrizSolucao);
  37. //Libera a memoria compartilhada
  38. shmctl(segmento, IPC_RMID, 0);
  39. return EXIT_SUCCESS;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement