Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #define DIMROW 100
  7. #define NUMROWS 20
  8.  
  9. typedef struct row {
  10. int vector[DIMROW];
  11. } row;
  12.  
  13. row matrix[NUMROWS];
  14.  
  15. int main() {
  16. int i, j, k, l;
  17. pid_t pid;
  18. int *value;
  19. int total_add;
  20. total_add = 0;
  21. // Initializing to 1 all the elements of the vector
  22. for (i =0; i < NUMROWS; i ++) {
  23. for (j =0; j < DIMROW; j ++) {
  24. matrix[i].vector[j] = 1 ;
  25. }
  26. }
  27.  
  28. for(k = 0; k < NUMROWS; k++){
  29. pid = fork();
  30. if(pid == 0){
  31. for(l = 0; l < DIMROW; l++){
  32. total_add += matrix[k].vector[l];
  33. }
  34. exit(total_add);
  35. }
  36. }
  37.  
  38. sleep(10);
  39. while(wait(value) > 0){
  40.  
  41. total_add += WEXITSTATUS(*value);
  42. }
  43. printf("the total add is %d", total_add);
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement