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

CS5001NA Networks and Operating System

20% Individual Coursework

2019-20 Autumn

Student Name: Narayan Tiwari

Group: L2N8

London Met ID: 18030944

College ID: NP01NT4S190030

Assignment Due Date:25th April

Assignment Submission Date: 24th April

Titles: UNIX script programming (Task A)

: Memory Management (Task B)

Word Count (Task B): 2108

confirm that I understand my coursework needs to be submitted online via Google Classroom under the
relevant module page before the deadline for my assignment to be accepted and marked. I am fully aware
that late submissions will be treated as non-submission and a mark of zero will be awarded.
Acknowledgement

This report is successfully completed with high encouragement, enthusiasm and


invaluable support of many individuals. I am very thankful to all of them. Especially, my
module leader Mr. Dipeshor silwal for providing the project contents and guidance
throughout the session. And I would also like to thank my lecturer Mr. suryansh Mathema
and my tutor Mr. Umesh Nepal for encouraging me to carry out research and providing
valuable assistance during the completion of my project. While doing my research, I got
many new things to learn and I am very positive with my work.

Furthermore, I would also like to express a debt of gratitude to my beloved friends,


seniors, my family and toward the whole Islington College family who have strongly
helped me to complete my project.
Abstract

This report combines the information based on two tasks. The first task is totally
based on development of script in the platform of well-known UNIX shell and the second
part includes the theoretical concept about memory management and its basic
fundaments. In the first task, it presents general introduction of UNIX operating system
along with descriptive information about its shell’s types like Bourne shell, Korn shell,
bash shell, C shell and other Shell. The body section consists of script which is developed
in accordance to the requirement and its testing by passing the script through various
tests along with their screenshot. At the end, the task A concluded with overall concept
of the project.

Task B includes the detail information about various concepts and techniques for
the management of memory inside the computer system. In the report, the structure of
memory management is welly described with its components. The process and method
of the memory allocation is described with their functions and purpose. Paging and
segmentation are also mentioned with their working structure and their importance to
control and manage the memory in the computer system.

Key Terms: UNIX OS, Bash shell, Bourne shell, Korn shell, C shell, Z shell, Fish shell,
Memory management, Memory allocation, Paging, segmentation.
Table of Contents
Task A ............................................................................................................................ 8

1. Introduction ................................................................................................................. 1
1.1 Introduction to UNIX operating system................................................................... 1
1.2 Shell and its types .................................................................................................. 2
1.3 Aims and Objective ................................................................................................ 3
1.3.1 Aims................................................................................................................. 3
1.3.2 Objective .......................................................................................................... 3
2. Description of scenario ................................................................................................ 4
3. Script ........................................................................................................................... 5
4. Testing ........................................................................................................................ 9
4.1 Test 1: Running the script without name ................................................................ 9
4.2 Test 2: Running the script with name and ID ....................................................... 10
4.3 Test 3: Incorrect password for 5 times. ................................................................ 11
4.4 Test 4: Running the script with correct password ................................................. 12
4.5 Test 5: Best team by country name ..................................................................... 13
4.6 Test 6: Best team by incorrect country code ........................................................ 14
4.7 Test 7: Best team by correct country code ........................................................... 15
4.8 Test 8: Selecting four players code ...................................................................... 16
4.9 Test 9: Selecting players with same name ........................................................... 17
4.10 Test 10: Wrong user (player) code ..................................................................... 18
4.11 Test 11: Passing right user (player) code........................................................... 19
4.12 Test 12: Player with no profile ............................................................................ 20
4.13 Test 13: Continue to redirect the program.......................................................... 21
4.14 Test 14: Continue to terminate the program ....................................................... 22
5. Contents of the three files ......................................................................................... 23
5.1 PK ........................................................................................................................ 23
5.2 VK ........................................................................................................................ 24
5.3 DW ....................................................................................................................... 25
6. Conclusion ................................................................................................................ 26
Task B ................................................................................................................. 27

1. Introduction ............................................................................................................... 28
2. Aim and Objective ..................................................................................................... 28
2.1 Aim ....................................................................................................................... 28
2.2 Objectives ............................................................................................................ 28
3. Background ............................................................................................................... 29
3.1 Hierarchy of Memory management ...................................................................... 29
3.2 Memory Allocation ............................................................................................... 31
3.2.1 Contiguous memory allocation....................................................................... 32
3.2.2 Non-contiguous memory allocation................................................................ 34
3.3 Dynamic storage allocation .................................................................................. 35
3.4 Paging .................................................................................................................. 37
3.5 Segmentation ....................................................................................................... 39
4. Conclusion ................................................................................................................ 42
5. References ................................................................................................................ 43
6. Abbreviations............................................................................................................. 46
7. Appendix ................................................................................................................... 47
7.1 Memory Controller ............................................................................................... 47
7.2 Virtual memory ..................................................................................................... 49
Table of figures
Figure 1: Testing for incomplete parameters entry ......................................................................9
Figure 2: Testing with complete parameters entry .....................................................................10
Figure 3: Testing with five invalid secret keys............................................................................11
Figure 4: Testing with valid secret key ......................................................................................12
Figure 5: Testing for the best team with country name ..............................................................13
Figure 6: Testing with incorrect country code ............................................................................14
Figure 7: Testing with correct country code ...............................................................................15
Figure 8: Testing with four players code entry ...........................................................................16
Figure 9: Testing with input of same player code ......................................................................17
Figure 10: Testing with wrong players code ..............................................................................18
Figure 11: Testing with valid players code.................................................................................19
Figure 12: Testing for player with no any profile ........................................................................20
Figure 13: Testing to redirect the program ................................................................................21
Figure 14: Testing to formally terminate from the program ........................................................22
Figure 15: Memory hierarchy ....................................................................................................30
Figure 16: Memory allocation types...........................................................................................31
Figure 17: Contiguous memory allocation .................................................................................33
Figure 18: Non-contiguous memory allocation ..........................................................................34
Figure 19: Paging hardware ......................................................................................................37
Figure 20: Prototype of paging model .......................................................................................38
Figure 21: Segmentation hardware ...........................................................................................40
Figure 22: Memory Controller layout .........................................................................................48
Figure 23: Virtual memory model ..............................................................................................50
Table of tables
Table 1: Testing no. 1 .................................................................................................................9
Table 2: Testing no. 2 ...............................................................................................................10
Table 3: Testing no. 3 ...............................................................................................................11
Table 4: Testing no. 4 ...............................................................................................................12
Table 5: Testing no. 5 ...............................................................................................................13
Table 6: Testing no. 6 ...............................................................................................................14
Table 7: Testing no. 7 ...............................................................................................................15
Table 8: Testing no. 8 ...............................................................................................................16
Table 9: Testing no. 9 ...............................................................................................................17
Table 10: Testing no. 10 ...........................................................................................................18
Table 11: Testing no. 11 ...........................................................................................................19
Table 12: Testing no. 10 ...........................................................................................................20
Table 13: Testing no. 11 ...........................................................................................................21
Table 14: Testing no. 12 ...........................................................................................................22
Task A
CS5001NI Network and Operating System

1. Introduction

1.1 Introduction to UNIX operating system

UNIX is the most powerful and popular multi-user and multi-tasking Operating
system which is truly the base of many Operating Systems like GNU/Linux, Ubuntu,
Solaris, etc. It was originally developed in the 1979s at AT&T Laboratories by Ken
Thompson and Dennis Ritchie and has been in continues development ever since. UNIX
was taken as the heart of the operating System and had a significant impact on other
operating system with inheriting various functions (Pandit, n.d.). The main concepts
through which all the version of UNIX interact within the system are classified into four
basics.

Kernel: It communicates with hardware and handles certain task like memory
management, task scheduling and file management.

Shell: The shell processes the user’s request from terminal, interpret them and calls the
program which the user want. C shell, Bourne Shell and Korn shell are the popular shell
used in the UNIX variants.

Command and Utilities: There are many commands like cp, mv, cat, grep and more
which are used in UNIX to conduct various operations.

Files and Directories: Files managed all the data whereas the directories organized all
those files. As whole the directories are organized by the filesystem (tutorialspoint.com).

1
Narayan Tiwari 18030944
CS5001NI Network and Operating System

1.2 Shell and its types


A shell is a program which provides as an interface between the user and the
operating system kernel. Whereas a Kernel is a program that deals with controlling all the
operations, coordinating utilities, scheduling and management of all system processes.
There are mainly six types of shell in UNIX operating system. They are.

Bourne shell

The Bourne shell is the original UNIX shell which was developed by Stephen
Bourne at Bell Labs. It is denoted by bsh. This shell is mostly preferred shell
because of it speed and compactness. But the major drawback of Bourne shell is
it lacks the use of interactive features such as it fails to call previous commands
(history). Its full name path is /bin/sh.

Bash shell

The Bash shell stands for Bourne again shell that carries many improved features
over the Bourne shell. Some of the major improvements includes Job control,
editing command-line, command history with unlimited size, etc. The shell is
denoted by bash. Its command full path name is /bin/bash.

C shell

The shell that enhanced the UNIX operating system and was originally developed
by Bill Joy at the University of California is known for C shell. It is a command
processor that runs in a command windows and has built-in arithmetic and C-like
expression syntax. Its full path name is /bin/csh.

Korn shell

The Korn shell is the superset of Bourne shell that was written and developed by
David Korn. The shell was originally written in the high-level programming
language. It includes most of the features of C shell (csh) but more powerful and
faster than C shell. The shell includes some convenient features like command-
line editing, job controlling, history mechanism and so on. The full pathname of the
command is /bin/ksh.

2
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Z shell

The Z shell is an interactive login shell which is an extension to Bourne shell with
many improvements. It is denoted by zsh. The Z shell combines features from
different shell-like Bash and ksh and is used as a command interpreter for shell
scripting. Some of its major features includes filename generation, function index,
spelling correction and approximate completion and so on.

Fish shell

The Fish shell (Friendly interactive shell) is a user-friendly shell that was
developed in 2005. It is an independent shell that is not based on other shell. It
holds different features like autosuggestions, supports 256 terminal technology,
tab competition abbreviations and many more (EDUCBA, 2020).

1.3 Aims and Objective


1.3.1 Aims
The main aim of this coursework is to obtain adequate knowledge about shell
scripting to develop the script based on given scenario and complete them within provided
timeframe.

1.3.2 Objective
The certain objectives that are made in order to obtain the aim of the task are
mentioned below.

• To research and learn about UNIX operating system along with the shell scripting.
• To practice and implement various commands of bash scripting to complete
different tasks as per the senior.
• To interact with the tutorials and module teachers to review and understand about
the scripts and their working methods.

Hardware Required: Pc with Window 10

Software Required for project: Debian, Ms-word, notepad++. Npp.7.8.5.dll

3
Narayan Tiwari 18030944
CS5001NI Network and Operating System

2. Description of scenario

The UNIX terminal is an interpreter that execute the created program in text files.
A shell script that establish interactive communication between its user and the UNIX
environment is to be written. A user must start with passing the program name along with
username and ID as the parameters. After correct entry, the program ask user to provide
secret key to get access inside the program. The right secret key allows user for next step
of the program or terminate the program only after obtaining five incorrect user input for
secret key. Welcome text is displayed with user provided name and ID along with date
and time of program execution.

With Welcome text, it displays the table of five cricket countries along with their
codes and ask the user to select the best team. As the best team in my program is Nepal.
Until the user entered the code of Nepal, the program runs in loop and ask for the correct
one. After Nepal is selected, the program moves into next step and displays the list of five
cricket players and ask user to choose three players from the list. The three chosen
players are listed as the menu and ask the user to choose any single player according to
their listed number. The user selects any single player by their listed number and the
program displays comment about the selected players and some descriptions about that
player. The program displays the description of player which is stored in the file of the
directory. If the file of selected player does not exist, then the program is set to show the
message about the absence of the file and ask user to run the program again. if any
invalid input is entered, then the program displays the error message. if user want to
continue the program then the program starts to run from the previous step of selecting
the country name or simply user can terminate from the program.

4
Narayan Tiwari 18030944
CS5001NI Network and Operating System

3. Script

The script that are implemented in each task of the scenario is given below.

• The best team is set to Nepal and its code is NEP.


• The three different files of Paras Khadka, Virat Kholi and David warner is created.

In CLI,

$ nano Cousework2

In GUI,

!/bin/bash #Implementing GNU Bourne Again shell(bash shell)


secret_key="" #Initializing the secret key to allow or deny the process.
count=0 #Initializing variable with name count
until [ "$secret_key" = "12345" ] # Until loop to check the secret key for
access or deny in the program.
do
echo -e "\nPlease, enter the secret key: \c"
read secret_key
count=`expr $count + 1`
if [ $count = 5 ] && [ $secret_key != "12345" ]
#if condition to check whether secret key is incorrect for 5 times.
then
echo "Warning! Mr./Mrs "$1", You have entered invalid
secret key for 5 times. Please, Confirm the valid secret key and try again."
exit
fi
done
echo -e "\n\t______________________________________\n"
echo -e "\t!!! YOU ARE WELCOME IN THE PROGRAM !!!"
echo -e "\t______________________________________\n"
echo -e "\nID = "$2" Name = "$1" Date =" $(date) "\n" #Displaying the
provided name and ID parameters along with default date and time.
if [ $# != 2 ] #if condition to check either the ID and name are
passed or not while executing the program.
then
echo "Name and ID not found! Please re-enter Name & ID respectively."
exit

5
Narayan Tiwari 18030944
CS5001NI Network and Operating System

fi
mainFunction() { #creating mainFuction that can be called to re-execute the
program at the end of the task.
cricket_countries() { #cricket_countries function is created for executing
the internal operations.
echo -e "\t -------------------------------------"
echo -e "\t| COUNTRY | CODE |"
echo -e "\t -------------------------------------"
echo -e "\t| Australia | AUS |"
echo -e "\t| Bangladesh | BAN |"
echo -e "\t| Nepal | NEP |"
echo -e "\t| India | IND |"
echo -e "\t| England | ENG |"
echo -e "\t -------------------------------------"
echo -e "\nGuess the best team from the table by their country
code.\n\c"
best_team="" #Initializing best_team as variable.
until [ "$best_team" = "nep" ] #until loop to check whether
choosen team is Nepal or not or invlaid input.
do
echo -e "Which is the best team in your prediction? \c"
read best_team
best_team=${best_team,,}
case $best_team in #case for checking best team.
nep)
echo -e "\n\t\t Well done!!! \nYour prediction is
Correct. Nepal might be your favourite team."
;;
AUS | BAN | IND | ENG)
echo -e "\nSorry! Your predication is
incorrect...\n"$best_team" is not the best team. \n""Try once again..."
;;
*)
echo -e "\nPlease enter the valid code."
;;
esac
done
echo -e "\n\t\t Nepal Cricket Team \n\t\t-------------------- \nNepal
is an emerging cricketing nation in the world. \nNepal had already
participated in different tournament \norganized by ICC. Sandeep lamichanne
is a popular player of Nepal.\n"
}
cricket_countries #end of Cricket_countries function
cricket_players() { #cricket_players function is created for executing
the files and operations of the program.
echo -e "\t ---------------------------------------"
echo -e "\t| PLAYERS | CODE |"
echo -e "\t ---------------------------------------"
echo -e "\t| Paras Khadka | PK |"

6
Narayan Tiwari 18030944
CS5001NI Network and Operating System

echo -e "\t| Virat Kohli | VK |"


echo -e "\t| David Warner | DW |"
echo -e "\t| Ben Stokes | BS |"
echo -e "\t| Ross Taylor | RT |"
echo -e "\t ---------------------------------------"
echo -e "\nChoose any three players using their code: \c"
read p v d #Initializing three variables as the input of the players.
choice=( $p $v $d ) #taking three variables as p, v and d
if [ ${#choice[@]} = 3 ] #checking whether the user has entered 3
codes of the player or not.
then
for check in $p $v $d
do
case $check in
PK | VK | DW | BS | RT)
;;
*)
echo -e "Invalid choices. please, try again.\n"
cricket_players
;;
esac
done
else
echo -e "Incomplete input. please, try again \n"
cricket_players #calling the cricket_players fuction.
fi
if [ $p = $v ] || [ $p = $d ] || [ $v = $d ] #checking for repeation
of the player codes
then
echo -e "Repeatation of name of same player found. Please, try
again\n"
cricket_players
fi
PS3="Select a best player from the choice: "
select single in "${choice[@]}"
do
case $single in
PK)
echo -e "Well. You select Paras Khadka as the
best player.\n"
cat PK #Files are called from the
directory
break
;;
VK)
echo -e "You select Virat Kholi as the
favourite player.\n"
cat VK
break

7
Narayan Tiwari 18030944
CS5001NI Network and Operating System

;;
DW)
echo -e "You select David Warner as the
best one.\n"
cat DW
break
;;
BS)
echo -e "Information about this player not
found. Please try again.\n"
mainFunction #calling the mainFunction
;;
RT)
echo -e "Information about this player not
found. Please try again.\n"
mainFunction
;;
*)
echo -e "The player you have entered is not
valid. Please try again\n"
esac
done
}
cricket_players
}
mainFunction
continue() { #continue function is created if the user like to repeat
the program again at the end.
echo -e "\nDo you want to continue (Y/N)?: \c"
read result
if [ $result = Y ] || [ $result = y ]
then
mainFunction
continue
elif [ $result = N ] || [ $result = n ]
then
echo -e "\nThank you for your presents. Hope to see you
again..!!!\n"
exit
else
echo -e "\nInvalid input. please, check and try again."
continue

fi
}
continue

8
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4. Testing

4.1 Test 1: Running the script without name


Purpose of Test: To check if the program terminates with an entry of single
parameter.

Test No. 1

Input Enter only one parameter i.e. ID while


running the script.

Expected Output Program will display an error message to


pass two parameters.
Actual Output Program displayed an error message to
pass two parameters.

Test Result Test is successful.

Table 1: Testing no. 1

Figure 1: Testing for incomplete parameters entry

9
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.2 Test 2: Running the script with name and ID


Purpose of Test: To display the name and ID after entering them as parameter
while running the script.

Test No. 2

Input Enter two parameters i.e. username and


ID along with filename.

Expected Output Program will display both parameters


along with execution date and welcome
message.
Actual Output Program displayed both parameters
along with execution date and welcome
message.
Test Result Test is successful.

Table 2: Testing no. 2

Figure 2: Testing with complete parameters entry

10
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.3 Test 3: Incorrect password for 5 times.


Purpose of Test: To check if the program exits with the input of invalid secret key
for five times.

Test No. 3

Input Input invalid secret key

Expected Output Program will be terminated showing the


error message about invalid secrete key.
Actual Output Program is terminated showing the error
message about invalid secrete key.

Test Result Test is successful.

Table 3: Testing no. 3

Figure 3: Testing with five invalid secret keys

11
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.4 Test 4: Running the script with correct password


Purpose of Test: To check if the correct secret key allows a user to access the
program.
Test No. 4

Input Enter the secret key as 12345

Expected Output It is supposed to allow for next step by


displaying welcome message with
username, ID and date and time of login.
Actual Output It allowed for next step by displaying
welcome message with username, ID
and date and time of login.
Test Result Test is successful.

Table 4: Testing no. 4

Figure 4: Testing with valid secret key

12
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.5 Test 5: Best team by country name


Purpose of Test: To check if the program request to enter the valid input until
correct country code is given.

Test No. 5

Input Enter any country name from the list.

Expected Output Program will display the error message


about invalid data entry and will ask until
the correct input is given.
Actual Output Program displayed the error message
about invalid data entry and asked until
the correct input is given
Test Result Test is successful.

Table 5: Testing no. 5

Figure 5: Testing for the best team with country name

13
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.6 Test 6: Best team by incorrect country code


Purpose of Test: To check if the program asks to predict the correct country code
until correct country code is given.

Test No. 6

Input Enter any country code from the list


except NEP.
Expected Output Program is expected to display the
message about prediction error and will
ask until the correct input is given.
Actual Output Program displayed the message about
prediction error and asked until the
correct input is given
Test Result Test is successful.

Table 6: Testing no. 6

Figure 6: Testing with incorrect country code

14
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.7 Test 7: Best team by correct country code


Purpose of Test: Passing the country code of Nepal as the best cricket team and
checking for description about Nepal by the program.

Test No. 7

Input Enter NEP as country code

Expected Output Program is expected to display the


description about NEP.
Actual Output Program displayed the description about
NEP.

Test Result Test is successful.

Table 7: Testing no. 7

Figure 7: Testing with correct country code

15
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.8 Test 8: Selecting four players code


Purpose of Test: To check the program if user input four players code.

Test No. 8

Input Enter four players code from the list.

Expected Output Program is supposed to show the error


message and will ask to re-enter three
players code from the list.
Actual Output Program showed the error message and
asked to re-enter three players code
from the list.
Test Result Test is successful.

Table 8: Testing no. 8

Figure 8: Testing with four players code entry

16
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.9 Test 9: Selecting players with same name


Purpose of Test: To check the program if user input same players code.

Test No. 9

Input Input the same player code for twice or


more
Expected Output Program is expected to display the error
message and will ask until three distinct
players code is given.
Actual Output Program displayed the error message
and asked until three distinct players
code is given.
Test Result Test is successful.

Table 9: Testing no. 9

Figure 9: Testing with input of same player code

17
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.10 Test 10: Wrong user (player) code


Purpose of Test: To check the program if a user inputs incorrect player code.

Test No. 10

Input Input random invalid codes.

Expected Output The program is expected to show error


message and will ask until right codes are
passed.
Actual Output The program shown error message and
asked until right codes are passed.

Test Result Test is successful.

Table 10: Testing no. 10

Figure 10: Testing with wrong players code

18
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.11 Test 11: Passing right user (player) code


Purpose of Test: To check the program if a user inputs correct player’s code.

Test No. 11

Input Input three valid player’s code.

Expected Output The program will display the selected


three codes of player in menu form.
Actual Output The program displayed the selected
three codes of player in menu form.

Test Result Test is successful.

Table 11: Testing no. 11

Figure 11: Testing with valid players code

19
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.12 Test 12: Player with no profile


Purpose of Test: To check the program if a user input player code that does not
contain any profile in the program.

Test No. 12

Input Input the player code whose profile file is


not created and select its number from
the menu.
Expected Output Program will prompt the message about
the missing of the file and will redirect the
program to step 4.
Actual Output Program displayed the message about
the missing of the file and redirected the
program to step 4.
Test Result Test is successful.

Table 12: Testing no. 10

Figure 12: Testing for player with no any profile

20
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.13 Test 13: Continue to redirect the program


Purpose of Test: To check if the program redirected to the previous step after the
user accept to continue by typing Y for the question “Do you want to continue?”

Test No. 13

Input Input Y after the question.

Expected Output Program is expected to redirect to the


previous step of selecting the country
name.
Actual Output Program was redirected to the previous
step of selecting the country name.

Test Result Test is successful.

Table 13: Testing no. 11

Figure 13: Testing to redirect the program

21
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4.14 Test 14: Continue to terminate the program


Purpose of Test: To check if the program formally terminates after the user wish
to continue by typing N for the question “Do you want to continue?”

Test No. 14

Input Input N after the question.

Expected Output Program is expected to normally


terminate with greeting message.
Actual Output Program was normally terminated with
greeting message.

Test Result Test is successful.

Table 14: Testing no. 12

Figure 14: Testing to formally terminate from the program

22
Narayan Tiwari 18030944
CS5001NI Network and Operating System

5. Contents of the three files

Three files were created among the five players where each file includes the
description of single player and are stored in the directory. In the program, a user is asked
to choose three players among the five players and the program list the selected players
into menu format. A user chose a single player by its list number and if chosen file exist
it show the information about the player which is mentioned below. If the doesn’t exist,
then the program display the message “File doesn’t exist”. The three files are given below:

5.1 PK

Paras Khadka

Paras Khadka is known as one of the best players Nepal has ever produced and is current
captain of the national side. A middle-order batsman who also bowls medium pace, he
represented Nepal in the Under-19 World Cups of 2004, 2006 and 2008 while also being
a part of the senior side.

---------------------------------------------------------
| Paras Khadka |
----------------------------------------------------------
| Full Name : Paras Khadka |
| Born : Oct 24, 1987 |
| Age : 33 years |
| Birth Place : Nepal |
| Height : 6 ft 3 in (1.91 m) |
| Role : Batting Allrounder |
| Batting Style : Right Handed Bat |
| Bowling Style : Right-arm fast-medium |
-----------------------------------------------------------

23
Narayan Tiwari 18030944
CS5001NI Network and Operating System

5.2 VK

Virat Kohli
Virat Kohli is an Indian cricketer who currently captains the India national team. A right-
handed top-order batsman, Kohli is regarded as one of the best batsmen in the world.

----------------------------------------------------
| Virat Kohli |
----------------------------------------------------
| Full Name : Virat Kohli |
| Born : Nov 05, 1988 |
| Age : 32 years |
| Birth Place : Delhi, India |
| Height : 5 ft 9 in (175cm) |
| Role : Batsman |
| Batting Style : Right Handed Bat |
| Bowling Style : Right-arm medium |
------------------------------------------------------

24
Narayan Tiwari 18030944
CS5001NI Network and Operating System

5.3 DW

David Warner

David Andrew Warner is an Australian international cricketer and a former captain of the
Australian national team. A left-handed opening batsman, Warner is the first Australian
cricketer in 132 years to be selected for a national team in any format without experience
in first-class cricket.

-------------------------------------------------------
| David Warner |
--------------------------------------------------------
| Full Name : David Andrew Warner |
| Born : Oct 27, 1986 |
| Age : 34 years |
| Birth Place : Australia |
| Height : 1.70 m |
| Role : Batsman |
| Batting Style : Left Handed Bat |
| Bowling Style : Right-arm leg break |
----------------------------------------------------------

25
Narayan Tiwari 18030944
CS5001NI Network and Operating System

6. Conclusion

Finally, the given coursework came to an end and was successfully completed
within time. This coursework helped in accessing decent knowledge about UNIX
operating system and to work with various in-built arithmetic and commands exist in the
operating system.

As per the scenario, a well-tested script is developed. All the given tasks are done
in bash shell. Different commands are implemented to complete the script. Functions and
loops like for, while, until, case, select etc. are used to compete different task. After script
is developed, it is passed with server testing approach to make it free from any errors.
Then the error free script is copy in textual form as mention in the script. The three files
of the best three player is also created where each player is detailly described. In this
way, Task A of this coursework is completed in required format with proper citations.

26
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Task B

27
Narayan Tiwari 18030944
CS5001NI Network and Operating System

1. Introduction

In an operating system, Memory management is the functionality of an OS that


controls and coordinate computer memory, assigning certain portions called blocks to
different running programs to maximize the overall operations of the system. The memory
management supports an operating system to manage primary memory and allows the
process to move back and forward between the main memory and execution disk. It helps
OS to tracks each memory location and decide whether the memory is allocated to certain
process or remains free. The memory management separate the total quantity of the
memory that is required to be allocated for the processes and determine which process
should get memory at what time. Various application and programs are stored in the
memory which are manage and control by the memory management and it also helps to
avoid any interfere between them (Guru99, 2020).

2. Aim and Objective


2.1 Aim
The main aim of this project is to research about memory management in an
operating system and prepare a report based on structure of memory management, its
allocation, paging and segments and its overall summary.

2.2 Objectives
The major objectives are:

• To conduct research from different source about the memory management and
its basic principle.
• To consult with modules leader and the teachers about contents of the report and
complete it within provided time.

28
Narayan Tiwari 18030944
CS5001NI Network and Operating System

3. Background

3.1 Hierarchy of Memory management


In computer system design, there has been implementation of a processor as well
as a huge amount of memory devices. The major problem is, these parts are so expensive
and complex. so, the concept of memory hierarchy is developed to organize the memory
such that it can improve the capacities and lower the cost and access time. The
development of memory hierarchy was based on behavior of the program known as
locality of references.

In the memory hierarchy design, the memory in the computer can be divided into
two types based on the speed as well as their use.

External Memory or Secondary Memory: This hierarchy comprises the peripheral


storages devices like Magnetic Disk, Optical Disk and Magnetic Tape which are
accessible by the processor via I/O modules.

Internal Memory or Primary Memory: It includes Main Memory, Cache Memory and
CPU registers which is directly accessible by the processor (Jain, n.d.).

The memory hierarchy design includes five hierarchies where the first three
hierarchies are volatile memories which mean in the condition of power unavailable, its
losses their stored data. whereas the last two hierarchies are not volatile that they store
data permanently. The following hierarchical pyramid is memory hierarchy diagram for
computer memory.

29
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Figure 15: Memory hierarchy

(Singhal, 2020)

The memory hierarchy in computers mainly includes the following components.

• Registers
Usually, the register is static RAM in the processor of the computer which use for
decision making as well as store the data like mathematical operations.
• Cache Memory
Cache memory is also found in the processor that holds the chuck of data which
are frequently used from main memory.
• Main Memory
The main memory is storage unit that stores the data throughout the operations of
the computer. It is made up of RAM as well as ROM.
• Magnetic Disk
The magnetic disks are circular plates fabricated of plastic where two faces of the
disk are utilized as well as stacked on one spindle by read or write heads gain on
each plane.
• Magnetic Tape
This tape is an ordinary magnetic recording which is mainly used to back up large
data (Elprocus, 2020).

30
Narayan Tiwari 18030944
CS5001NI Network and Operating System

3.2 Memory Allocation

Memory allocation is a process of assigning the physical or the virtual memory


address space to the computer program and services. It is an action of preserving a
partial or whole segment of computer memory for operation of programs and processes.
Memory allocation is done by the process called memory management. it is basically an
operation of computer hardware that is control and operate by operating system and
software applications (T, 2020).

Memory allocation has two fundamental methods for allocating the memory. They are:

Figure 16: Memory allocation types

(T, 2020)

31
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Static memory allocation

This method allocates the memory to a process before its execution or at compile time of
the program.

Dynamic memory allocation

This method allocates the memory to a process during its execution or at run time of the
program (Techopedia, 2020).

In the computer program, the multiple user can share the memory simultaneously.
it means there will be more than one process in the main memory and to handle the event
likes I/O, CPU will make context switch and step toward next processes. So, memory
allocation possesses the technique for allocating the blocks of memory on the request to
the process. The main memory in the system is allocated based on two methods.

3.2.1 Contiguous memory allocation

In contiguous memory allocation, all the available memory spaces are allocated in
one place. When a process is requested by any user for a memory a single portion of the
contiguous memory block is assigned for that process based on its requirements.
Contiguous memory allocation can be achieved by diving memory into two partitioning
methods.

32
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Figure 17: Contiguous memory allocation

(Jain P. , 2019)

Fixed sized partition

In this partition, the memory is divided into fixed sized where whole partition is
implemented to a process and if there is some spare partition remains then it called
internal fragmentation.

Variable size partition

In variable size partition, the memory is taken as single unit and partition allocated
to the process is exactly similar as per requirements and the unoccupied space can be
used again.

33
Narayan Tiwari 18030944
CS5001NI Network and Operating System

3.2.2 Non-contiguous memory allocation

In the non-contiguous memory allocation, all the available free memory spaces are
randomly allocated and are not place at fixed pattern. The process can acquire the
memory space at different locations. So, it consumes more time to allocate the memory.
This method can utilize all the free memory space and helps to eliminate the problem of
message wastage which leads to internal and external fragmentation (Jain P. , 2019).

Figure 18: Non-contiguous memory allocation

(Jain P. , 2019)

34
Narayan Tiwari 18030944
CS5001NI Network and Operating System

3.3 Dynamic storage allocation

Dynamic storage allocation is performed when the program request to operating


system to allocate a block of main memory for execution of the program. It provides
flexibility to execution of the program. As it can determine the amount of memory space
required by the program. When the memory size of the program is large enough than a
dynamic memory allocation is implemented on various section of the program according
to the requirements. This usually helps to minimize the memory wastage and improve the
performance of the system. Furthermore, Dynamic memory allocation enable operating
system to select a best hole or block when more than one empty hole or block are
available for an active process. While allocating memory dynamically, it can generate
overhead within the system. The repetition of allocation operation can create more
overheads which lead to slow execution of the program (T, 2020).

The methods through which holes or blocks of the memory are allocated to
determine its best allocation are:

➢ First fit

In the first fit approach, it allocates the first free partition or hole which is large
enough that can hold suitable process. it usually completes after finding the first relevant
hole.

Advantage

• It is faster because it has limited search.

Disadvantage

• If the memory is too small, then the unused memory area after allocation
become wastage.

35
Narayan Tiwari 18030944
CS5001NI Network and Operating System

➢ Best fit

In the best fit approach, it allocates the smallest free partition that fulfil the need of
the requesting process. the method searches the whole list of available partition and
consider the smallest hole that is suitable. It then tries to recognize a hole which adequate
to required actual process sized.

Advantage

• It has better memory utilization that can quickly search the first available
smallest free partition.

Disadvantage

• It is slower that tends to fill unwanted tiny holes in the memory.

➢ Worst fit

In the worst fit approach, it allocates the large free portion so that available portion
will be full enough to be useful. It is opposite of best fit.

Advantage

• It eliminates small gapes.

Disadvantage

• It cannot handle process that requires larger memory at a later stage as the
larger hole will be already occupied (Tutorials Point, 2020).

36
Narayan Tiwari 18030944
CS5001NI Network and Operating System

3.4 Paging

Paging is the memory-management scheme that permit a process to be stored in


a memory in a non-contiguous manner. it solves the problem of external fragmentation
and need for compaction. It also avoids the considerable problem of allocating memory
blocks of different sizes onto the backing store. For implementing the paging involves
breaking of the physical and logical memory spaces into fixed-sized blocks. These block
of same size of physical memory are called frames and the similar size blocks of logical
memory are called pages. when a process is to be executed, its pages are loaded into
frames of the available physical memory space from logical memory space. Every
address created by the CPU to access the frame is divided into two parts i.e.

Page number (p): it is used as an index into a page table.

Page offset (d): it mixed with base address to determine the physical memory address
(Shareef).

Figure 19: Paging hardware

(Shareef)

37
Narayan Tiwari 18030944
CS5001NI Network and Operating System

The page number in the page tables is used as an index. Each process contains
its distinct page table that outline logical address to the physical address. The page tables
hold the base address of the page contained by the frame of physical address. The page
table defines the base address that combines with page offset to specify the frame
number in physical memory which has stored the page (Tech Differences, 2020).

Example of paging is illustrated below.

Figure 20: Prototype of paging model

(Shareef)

38
Narayan Tiwari 18030944
CS5001NI Network and Operating System

3.5 Segmentation

Segmentation is a memory management scheme that allocate the physical


memory to the process in non-contiguous manner. it divides the logical address spaces
into several small blocks called segments. A segment can be defined as logical division
that enables grouping of information such as a subroutines, procedure, function, array or
data area. Segments are of variable size and individually allocates the memory. Because
of the unequal size, it is like a dynamic partitioning. It avoids internal fragmentation but
experience external fragmentation. In segmentation, a logical address consists of two
parts: a segments number and an offset. Main memory includes a distinct segment
location for an offset (E-computer Concepts, 2020). Segments are generated at time of
program translation by combining logically related items. Segmentation is transparent and
is available for managing programs and data.

An address mapping hardware is used for implementing a segment address space.


Segment table maps the two-dimensional user-defined addresses into single dimensional
physical address. It includes the limit of segment and a segment base. The segments
base contains the starting physical address where segments limits defines the segment’s
length.

39
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Figure 21: Segmentation hardware

(Silberschatz, Gagne, & Galvin)

A logical address in the segment (d) contains two parts i.e. segment number (s)
and offset. Segment number is used as an index in the segment table where each entry
of segment table must provide initial address in the main memory of the respective
segment (Godse & Godse, 2010).

Advantages

• It eliminates internal fragmentation.


• it is easier to relocate segments than entire address space.
• It enables less processing overhead.

40
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Disadvantages

• It may include external fragmentation.


• It becomes costly technique in management of memory.
• It is difficult for allocation of contagious memory to partition due to its unequal
size (VIVADIFFERENCES.COM, 2019).

41
Narayan Tiwari 18030944
CS5001NI Network and Operating System

4. Conclusion

In the Task B of this coursework, a well research and continuous study about
various methods for the management of memory within an operating system is carried
out. It has broadened my knowledge and helped in completing the report as per the
requirements. Memory is an important fundament of the computer system and the
management of the memory helps to control and handles various operation in the system.
So, the overall report deals with processes and measures for managing the memory in
the best way possible.

This report explains about the Memory management concept, their purpose,
working scheme and techniques to manage the memory for best performance and
optimum benefits to the system. The hierarchy of memory in the report helps in
understanding the structure of different components of memory management. Memory
allocation to the process is defined through different method to analysis best memory
storage methods. Memory management scheme like paging and segmentation helps to
utilizes the memory in different level by interactive participation with memory
management components. The report is finally completed after a several days research
from books, journals, websites, other resources and constant interaction with the module
teachers.

42
Narayan Tiwari 18030944
CS5001NI Network and Operating System

5. References
(n.d.).

Chacko, C. (2020). SlideShare. (LinkedIn Corporation) Retrieved Jan 8, 2018, from www.slideshare.net:
https://www.slideshare.net/ChessinChacko/intel-8th-generation-and-7th-gen-microprocessor-
full-details-especially-for-taking-seminars

COMPUTER BUSINESS REVIEW. (2020, April 17). CBR. (COMPUTER BUSINESS REVIEW) Retrieved 1993,
from www.cbronline.com: https://www.cbronline.com/what-is/what-is-virtual-memory-
4929986/

E-computer Concepts. (2020). E-computer Concepts. (Temple Genix) Retrieved August 24, 2019, from
ecomputerconcepts.com: https://ecomputerconcepts.com/segmentation-in-memory-
management/

EDUCBA. (2020). EDUCBA. Retrieved from www.educba.com: https://www.educba.com/types-of-shells-


in-linux/

Elprocus. (2020). Elprocus. (Elprocus) Retrieved 2013, from www.elprocus.com:


https://www.elprocus.com/memory-hierarchy-in-computer-architecture/

Godse, A. P., & Godse, D. A. (2010). Computer Organization (1st ed.). Technical Publications. Retrieved
from https://books.google.com.np/books?id=AIHgbyyEIHoC&pg=RA1-SA9-
PA43&dq=paging+and+segmentation&hl=en&sa=X&ved=0ahUKEwj3j8moqOzoAhWFzzgGHajcA
xQQ6AEIVTAF#v=onepage&q=paging%20and%20segmentation&f=false

Guru99. (2020). Guru99. (Guru99 ) Retrieved from www.guru99.com: https://www.guru99.com/os-


memory-management.html#1

Inphi. (2014). Introduction to design considerations of DRAM memory controllers. 56. Inphi. Retrieved
from https://sci-hub.tw/10.1109/cicc.2014.6946076

Jain, P. (2019, april 23). IncludeHelp.com. (IncludeHelp ) Retrieved march 06, 2015, from
www.includehelp.com: https://www.includehelp.com/operating-systems/contiguous-and-non-
contiguous-memory-allocation.aspx

Jain, R. (n.d.). GeeksforGeeks. (geeksforgeeks.org) Retrieved from www.geeksforgeeks.org:


https://www.geeksforgeeks.org/memory-hierarchy-design-and-its-characteristics/

43
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Pandit, N. (n.d.). GeeksforGeeks. (geeksforgeeks.org) Retrieved from www.geeksforgeeks.org:


https://www.geeksforgeeks.org/introduction-to-unix-system/

PCMag.com. (2020). PCMag. (ZIFF DAVIS, LLC. PCMAG DIGITAL GROUP) Retrieved 1996, from
www.pcmag.com: https://www.pcmag.com/encyclopedia/term/virtual-memory

Rubens, P. (2020). Enterprise Storage. (Quinstreet Inc) Retrieved May 17, 2019, from
www.enterprisestorageforum.com: https://www.enterprisestorageforum.com/storage-
hardware/virtual-memory.html

Shareef, H. (n.d.). Operating Systems. Retrieved from


http://www.uobabylon.edu.iq/eprints/publication_3_28232_1410.pdf

Silberschatz, A., Gagne, G., & Galvin, P. B. (n.d.). Main memory. 9th. Retrieved from
https://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/8_MainMemory.html

Singhal, A. (2020). Gate Vidyalay. (Gate Vidyalay) Retrieved from www.gatevidyalay.com:


https://www.gatevidyalay.com/memory-hierarchy-memory-hierarchy-diagram/

T, N. (2020). Binary Terms . (Binary Terms) Retrieved Aug 13, 2019, from binaryterms.com:
https://binaryterms.com/static-and-dynamic-memory-allocation.html

Tech Differences. (2020). Tech Differences. (Tech Differences) Retrieved December 26, 2016, from
techdifferences.com: https://techdifferences.com/difference-between-paging-and-
segmentation-in-os.html#Definition

Techopedia. (2020). (Techopedia Inc.) Retrieved from www.techopedia.com:


https://www.techopedia.com/definition/27492/memory-allocation

Tutorials Point. (2020). tutorialspoint. (Tutorials Point) Retrieved from www.tutorialspoint.com:


https://www.tutorialspoint.com/operating_system/os_memory_allocation_qa2.htm

tutorialspoint.com. (n.d.). Unix Tutorial. tutorialspoint.com. Retrieved from


https://www.damits.ac.in/library_doc/unix.pdf

VIVADIFFERENCES.COM. (2019). VIVADIFFERENCES. (VIVADIFFERENCES.COM) Retrieved from


vivadifferences.com: https://vivadifferences.com/difference-between-paging-and-
segmentation-in-os/

44
Narayan Tiwari 18030944
CS5001NI Network and Operating System

VIVADIFFERENCES.COM. (2019). VIVADIFFERENCES. (VIVADIFFERENCES.COM) Retrieved from


vivadifferences.com: https://vivadifferences.com/difference-between-cache-memory-and-
virtual-memory-in-computer-architecture/

45
Narayan Tiwari 18030944
CS5001NI Network and Operating System

6. Abbreviations

GNU : GNU's Not UNIX

FISH : Friendly Interactive Shell

PC : Personnel Computer

OS : Operating System

I/O : Input and Output

CPU : Central Processing Unit

RAM : Random Access Memory

ROM : Read Only Memory

IMC : Integrated Memory Controller

MCC : Memory Chip Controller

MCU : Memory Controller Unit

46
Narayan Tiwari 18030944
CS5001NI Network and Operating System

7. Appendix

7.1 Memory Controller

Memory Controller is defined as a digital circuit that handle the stream of


information going to and from the computer’s primary memory. It can be partitioned
chip or combined into another chip which is being place on the same die or as an
indispensably portion of microprocessor. It is usually called as an integrated
memory controller (IMC). A memory controller is also known as a memory chip
controller (MCC) or a memory controller unit (MCU) (Chacko, 2020). it is a widget
that helps to manages certain requests of the operator and accounts for the
constraints generated by the memory devices. Its facilities for functionable and
dependable operations for both hosts and memory devices that helps to optimize
the preformation and power. We need to understand basic components for
designing a good memory controller such as host requirements, memory device
constraints and their connectivity through interfaces (Inphi, 2014).

A diagram that depicts the basic structures and its operations in memory controller
is mention below.

47
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Figure 22: Memory Controller layout

(Inphi, 2014)

48
Narayan Tiwari 18030944
CS5001NI Network and Operating System

7.2 Virtual memory

Virtual memory is provision of an operating system that allows a computer


to be capable to manage the shortage of physical memory by shifting pages of
data from random access memory (RAM) to secondary memory storage such as
a hard disk or solid-state drive. It is a temporary process and designed to work as
a mutual combination of RAM and space on secondary memory storage. RAM
stores the data that is required to run the application. When the larger application
must run or many applications are running at once, the RAM has to face shortage
of memory. To compensate the problem, some inactively used data from RAM can
be transferred to virtual memory. This process enables for RAM to be free up space
so that it can be used to accommodate data that the system required to access
inherently (COMPUTER BUSINESS REVIEW, 2020).

Virtual memory can be implemented from both software and hardware


prospective. All modern, generally available CPUs have memory management
units (MMUs) that consists the virtual memory. They include “page table” that are
used to translate virtual address into physical address. As initially the program load
in a contagious block of code, it can wrap up in pages that are irrespectively
dispersed around RAM. Virtually memory is usually implemented by demanding
paging and demand segmentation (PCMag.com, 2020).

The below figures show the structural diagram of virtual memory within the
computer system.

49
Narayan Tiwari 18030944
CS5001NI Network and Operating System

Figure 23: Virtual memory model

(VIVADIFFERENCES.COM, 2019)

Advantage of Virtual Memory

• It enables multiple application to run at the same time.


• It enables to run larger application by coordinating between primary and
secondary storage space.
• It is cost effective that avoid the needs for buying more RAM.

Disadvantage of Virtual Memory

• It cannot provide the similar performance as RAM.


• It badly affects the whole performance of a system.
• It occupies storage space that can be used as storage for long term data
(Rubens, 2020).

50
Narayan Tiwari 18030944
CS5001NI Network and Operating System

51
Narayan Tiwari 18030944

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