Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define DIMROW 100
- #define NUMROWS 20
- typedef struct row {
- int vector[DIMROW];
- } row;
- row matrix[NUMROWS];
- int main() {
- int i, j, k, l;
- pid_t pid;
- int *value;
- int total_add;
- total_add = 0;
- // Initializing to 1 all the elements of the vector
- for (i =0; i < NUMROWS; i ++) {
- for (j =0; j < DIMROW; j ++) {
- matrix[i].vector[j] = 1 ;
- }
- }
- for(k = 0; k < NUMROWS; k++){
- pid = fork();
- if(pid == 0){
- for(l = 0; l < DIMROW; l++){
- total_add += matrix[k].vector[l];
- }
- exit(total_add);
- }
- }
- sleep(10);
- while(wait(value) > 0){
- total_add += WEXITSTATUS(*value);
- }
- printf("the total add is %d", total_add);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement