Está en la página 1de 4

QEEE Assignment

1. We learnt in class that the OS is a big program. However there are


differences between a regular user space program that we write and
the OS. Enumerate the differences in short sentences.
a. OS
● The Operating System is the System Software that makes the Computer work.
We can say that an Operating System (OS) is Software that acts as an interface
between you and the hardware.
● It not only contains drivers used to speak the hardware's language, but also
offers you a very specific graphical user interface (GUI) to control the
computer. An OS can also act as an interface (from the hardware) to the other
software.
● A complex OS like Windows or Linux or Mac OS offers the services of an
OS, but also has applications built in. Solitaire, Paint, Messenger, etc. are all
applications.

● Application software is the software that you install onto your Operating
System.
● It consists of the programs that actually let you do things with your computer.
● These Applications are written to run under the various Operating Systems.
These include things like your word processing programs, spreadsheets, email
clients, web browser, games, etc.
● Many programs, such as most of the Microsoft Office suite of programs, are
written in both Mac and Windows versions, but you still have to have the right
version for your OS.
2. Write a program that forks exactly N processes, where N is an input
taken from a user.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

#define BIT(t, j) ((t>>j) & 1)

long long convertDecimalToBinary(int n)


{
long long binaryNumber = 0;
int remainder, i = 1, step = 1;
int bit_size_N = 0;

while (n!=0)
{

remainder = n%2;
n /= 2;
binaryNumber += remainder*i;
i *= 10;
bit_size_N++;
}
return bit_size_N;
}

int main () {

int N;
scanf(%d”,&N)

int i;
int bit_size;
int process = 0;

bit_size = convertDecimalToBinary(N);

pid_t gpid;

gpid = getpid();

for(i=bit_size -2 ; i>=0;--i) {

fork();
if(BIT(N, i) && gpid == getpid())

{
fork();

process++;

}
}
printf(" Number of processes = %d\n",process);
return 0;

}
3) Consider the following set of processes, with the arrival time and length
of the CPU burst times given in milliseconds. Draw the Gantt chart to
illustrate the execution of these processes for the multi-level priority
scheduling queue scheduling algorithm without feedback.

2 2 2 3 4 2 2 2
P1 P2 P3 P4 P3 P2 P5 P1
4) Write a program that has accepts two numbers X and Y from the user.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

int X, Y;

int main(int arggc, char **argv){

char buffer [33];


pid_t c1, c2;

scanf("%d %d", &X,&Y);


c1 = fork();
switch(c1) {
case 0:
X = X + Y;
exit(0);
default:
c2 = fork();
if (c2 == 0) {
Y = X - Y;
exit(0);
}
}
wait(NULL);
wait(NULL);
printf("%d %d\n", X,Y);
}

5. Consider the following solution for the critical section.

● This method is good to ensure mutual exclusion but does not guarantee
progress.
● This solution ensures mutual exclusion; but does not guarantee progress. For
instance, what if process with PID=0 exits. All other processes would
eventually wait infinitely in the while loop when turn=0.

También podría gustarte