You are on page 1of 5

PART 1: Multiple choice.

c. Many user threads can access the


1. In a many-to-one threading model kernel at a time
a. Many user threads exist d. Many user threads are able to run in
b. Many kernel threads are provided for a parallel
user thread

2. A bootstrap program can be stored initially on


a. Cache c. EEPROM
b. RAM d. None of the above

3. Is not part of stack data


a. Function parameters c. Local variables
b. Return addresses d. Global variables

4. A process that spends most of the time doing computations is called


a. Memory-bound process c. I/O-bound process
b. CPU-bound process a. None of the above

c. transferring blocks of data from buffer


5. Caching is: storage directly to main memory without
a. requesting the operating system to allow CPU intervention
user to wait for I/O completion d. multiple systems working together to
b. copying information into faster storage provide high-availability service and
system survive failures
Questio Answer
n
1 a
Answers to multiple choice 2 c questions

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;

public class JavaThreading {

public static void main(String[] args) throws InterruptedException {


Scanner input = new Scanner(System.in);
float a, b, c;
System.out.println("enter a: ");
a = input.nextFloat();
System.out.println("enter b: ");
b = input.nextFloat();
System.out.println("enter c: ");
c = input.nextFloat();
numerator n = new numerator(a, b, c);
denominator d = new denominator(a, b, c);
n.start();;
d.start();
n.join();
d.join();
float res = n.getNume() / d.getDeno();
System.out.println(res);

}
package javathreading;

public class numerator extends Thread {

private float res;

3
private float a, b, c;

public numerator(float a, float b, float c) {


this.a = a;
this.b = b;
this.c = c;
}

public void run() {


res = (float) (a + Math.pow(b, 2) + Math.pow(c, 3));
}

public float getNume() {


return res;
}

package javathreading;

public class denominator extends Thread {

private float a, b, c;
private float res;

public denominator(float a, float b, float c) {


this.a = a;
this.b = b;
this.c = c;
}

public void run() {


res = a + 2 * b + 3 * c;

public float getDeno() {


return res;
}

4
}

You might also like