Вы находитесь на странице: 1из 7

Date: October 16, 2018

Assignment # 01
Class ID: 102540
Subject: Operating System
Group Members:
1. M. Bilal Khan(62708)
2. Rohma Zahid(62648)
3. Fawad Baig(62669)

Submitted To:
Sir Ayaz Khan
Table of Contents
TABLE OF CONTENTS ............................................................................................................. 2
1. TASK 01 ................................................................................................................................. 3
1.1. PART 1............................................................................................................................. 3
1.1.1 CODE ........................................................................................................................ 3
1.1.2 EXPLANATION ........................................................................................................... 3
1.1.3 OUTPUT ..................................................................................................................... 4
1.2. PART 02 ........................................................................................................................... 5
1.2.1 SOURCE CODE ......................................................................................................... 5
1.2.2 EXPLANATION ........................................................................................................... 5
1.2.3 OUTPUT ..................................................................................................................... 6
1.3. GRAPH AND TABLE ..................................................................................................... 10
Task 1:
CODE SNIPPET:
DEPENDENCIES:
#include<time.h>

#include<stdlib.h>

#include<stdio.h>

#include<unistd.h>

MAJOR FUNCTIONS:
//INITIALIZATION:
void initialize(int T[][N]) {

int i, j;

for (i = 0; i < N; i++) {

for (j = 0; j < N; j++) {

T[i][j] = rand() % 100;}

//ADD / SUB /MUL:

void Add(int T[][N], int X[][N], int Y[][N]) {

int i, j;

for (i = 0; i < N; i++) {

for (j = 0; j < N; j++){

T[i][j] = X[i][j] + Y[i][j];}

SAME AS OTHER Subtraction and Multiplication function/Methods :

SHORT EXPLAINATION:
We have calculated three different times with different array sizes.

Task # 1 was to calculate two matrixes and store their result in third matrix.
The graph below shows the output of three different array size calculations.
In task # 1, we had to subtract, add and multiply two matrixes and execute the code in a single process
and calculate its processing time. We divided the calculations in four different methods to make the code
easier to read and understand.
We divided the code in four different methods: Addition, Subtraction, Multiplication and Random Inputs in
a matrix.
At the end of the program we can see the process time taken for calculating there different operations in a
single process.
Methods are called in main and values has been passed to each method for different calculations through
parameters.

OUTPUT:
Task 2:
CODE SNIPPET:
//MAKE CHILD PROCESS
t = clock();

if(pid==0)

{Add(C,A,B);}

if(pid>0){

pid=fork();

if (pid==0)

{ sub(C,A,B);}

pid=fork();

if (pid==0)

{multi(C,A,B);}

t = clock() - t;

SHORT EXPLAINATION:

This task is similar like the previous task but here we have calculated three different processes in a single
execution file. We have used Fork system call to create child process.
Clock is initialized and calculating the processing time of execution of three different process created by
fork. Fork system call is used for creating a new process, which is called child process, which runs
concurrently with the process that makes the fork() call (parent process).
This time we have created three different processes which all will execute simultaneously.
After a new child process is created, both processes will execute the next instruction following the fork()
system call.
A child process uses the same pc (program counter), same CPU registers, and same open files which
use in the parent process.
The condition is checking on success, the pid of the child process is returned in the parent’s thread of
execution, and a 0 is returned in the child’s thread of execution.
OUTPUT:
Size 1024:

Size 2048:

Size 4096:
GRAPH AND TABLE

450
400 Chart Title
350
300
250
Time

200
150
100
50
0
1024 2048 4096
Single Process 4.3 50.67 428.11
Multi Process 0.001328 0.0031 0.00989

Comments:

The chart show the changes in the execution timing of program / Single Process program , Multi Process
Program . It can be seen that the Single process time of execution increase gradually . While the Multi process
time is approx zero(0) between 1024 and 2048. But when the size is 4096 or above the Single Process is
rocketed increased when Multi Process is slightly increase. As the result , it would we be quite true to say that
the Multi Process more efficient program and take few time as compared to single process time .

Вам также может понравиться