Given a list of integers find the Minimum Maximum and the Su

Given a list of integers find the Minimum, Maximum, and the Sum of the numbers. The list will be in a text file you generate. You may use any form of interprocess communication (IPC) to partition the file/array into chunks and distribute work to more than one processes (if there are multiple ones) (e.g.. pipes, shared memory, or additional (perhaps more sophisticated) inherent process system calls). Input Format: Input will be in a text file. Each integer will be separated by a newline character (\ ). 100 20 35 Output Format: You should print out the results in a text file. Every process that is created should print out their own process id and their parent\'s process id. Then once you have computed the final max, min, and sum, you will print those out. Please follow this format: Hi I\'m process 2 and my parent is 1. Hi I\'m process 3 and my parent is 2. Hi I\'m process 4 and my parent is 2. Max = 50 Min = 1 Sum = 371

Solution

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
int main()
{
    FILE *fp, *fp1;
    int i = 0, j, num[10], total = 0, max, min;
    char word[32];
    fp = fopen(\"text\", \"r\"); //open text in read mode
    fp1 = fopen(\"text1\", \"a+\");// open text1 in append mode
    if(fork()==0){
        i=0;
        fprintf(fp1, \"\ Hi i\'m process %d and my parent is %d\ \", getpid(), getppid()); //write data into text1 file
        while(fscanf(fp, \"%s\", word)!=EOF) //read the data from text file
            num[i++] = atoi(word);
        max = num[0];
        for(j=0; j<i; j++)
            if(num[j] > max) // find the max number from file
               max = num[j];
      
    }
    else
    {
      
        if(fork()==0){
           i=0;
            fprintf(fp1, \"\ Hi i\'m process %d and my parent is %d\ \", getpid(), getppid());
            while(fscanf(fp, \"%s\", word)!=EOF)
              num[i++] = atoi(word);
            min = num[0];
            for(j=0; j<i; j++)// find the min num
                if(num[j] < min)
                    min = num[j];
            rewind(fp);     
          
        }
        else{
            i=0;
            fprintf(fp1, \"\ Hi i\'m process %d and my parent is %d\ \", getpid(), getppid());
            while(fscanf(fp, \"%s\", word)!=EOF)
              num[i++] = atoi(word);
          
            for(j=0; j<i; j++) // find the sum
                total = total + num[j];
            rewind(fp);     
           
        }
    }
     fprintf(fp1, \"Max= %d\ \", max);
     fprintf(fp1, \"Min=%d\ \", min);
     fprintf(fp1, \"Sum=%d\ \", total);
}

 Given a list of integers find the Minimum, Maximum, and the Sum of the numbers. The list will be in a text file you generate. You may use any form of interproc
 Given a list of integers find the Minimum, Maximum, and the Sum of the numbers. The list will be in a text file you generate. You may use any form of interproc

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site