Professional Documents
Culture Documents
3 d
4 c
5 b
1
PART 2: Processes
Write a C program that will creates a child process. The parent will ask the user to enter 3
integers a, b and c and then sends them to the child. The child should find the maximum
between a, b and c.
The inter-processes communication should be using pipes.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
int fda[2];
int fdb[2];
int fdc[2];
pipe(fda);
pipe(fdb);
pipe(fdc);
int i=fork();
if (i > 0) {
int a,b,c;
printf ("enter a :") ;
scanf("%d",&a);
write(fda[1], &a, sizeof(int));
printf ("enter b :") ;
scanf("%d",&b);
write(fdb[1], &b, sizeof(int));
printf ("enter c :") ;
scanf("%d",&c);
write(fdc[1], &c, sizeof(int));
}else {
int d,e,f;
read(fda[0], &d, sizeof(int));
read(fdb[0], &e, sizeof(int));
read(fdc[0], &f, sizeof(int));
int max=(d>e && d>f)? d :(e>d && e>f)? e:f;
printf("d is the max %d",max);
}
sleep(1);
return 0;
}
Part 3:
2
Write a JAVA program that reads four float numbers (a, b, and c) and calculates the following equation:
a+b 2+ c3
a+2 b+3 c
To calculate the result, this program creates two threads: numerator and denominator.
The thread Numerator calculates [ a+ b2 +c 3 ]
The thread Denominator calculates [ a+ 2b+ 3 c ]
Once the threads finish their jobs, the program divides the result obtained from Numerator by the value
obtained from denominator. Then it prints the result.
package javathreading;
import java.util.Scanner;
}
package javathreading;
3
private float a, b, c;
package javathreading;
private float a, b, c;
private float res;
4
}