Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

OS File Shivali 2237750

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 85

Department of Information Technology

Task No:- 01
Aim: Installation Process of various operating systems.

Theory: An operating system (OS) manages all other applications and programs in a computer,
and it is loaded into the computer by a boot program. It enables applications to interact with a
computer’s hardware. Through a designated application programme interface, the application
programmes request services from the operating system (API). 

Figure 1.1

EXAMPLES: Five of the most common operating systems are Microsoft Windows, Apple
macOS, Unix, Linux and Android.

Windows: Windows is a graphical operating system developed by Microsoft. It allows users to


view and store files, run the software, play games, watch videos, and provides a way to connect to
the internet. It was released for both home computing and professional works.

Mac OS: Mac OS is the operating system for Apple’s Macintosh line of PCs and workstations.

Unix: Unix is a multiuser operating system designed for flexibility and adaptability. Unix was one
of the first operating systems to be written in C language.

Linux: Linux is a Unix-like, open source and community-developed operating system (OS) for
computers, servers, mainframes, mobile devices and embedded devices.

Android: Android is a mobile operating system based on a modified version of the Linux


kernel and other open-source software, designed primarily for touchscreen mobile devices

Shivali Kumari 2237750 Page 1


Department of Information Technology

Types of Operating System (OS):

 Batch Operating System


 Multitasking/Time Sharing OS
 Multiprocessing OS
 Real Time OS
 Distributed OS
 Network OS
 Mobile OS

1. Batch Operating System:

Some computer processes are very lengthy and time-consuming. To speed the same process, a job
with a similar type of needs are batched together and run as a group. The user of a batch operating
system never directly interacts with the computer. In this type of OS, every user prepares his or
her job on an offline device like a punch card and submit it to the computer operator.

2. Multi-Tasking/Time-sharing Operating systems:

Time-sharing operating system enables people located at a different terminal(shell) to use a single
computer system at the same time. The processor time (CPU) which is shared among multiple
users is termed as time sharing.

3. Real time Operating System:

A real time operating system time interval to process and respond to inputs is very small.
Examples: Military Software Systems, Space Software Systems are the Real time OS example.

4. Distributed Operating System:

Distributed systems use many processors located in different machines to provide very fast
computation to its users.

5. Network Operating System:

Network Operating System runs on a server. It provides the capability to serve to manage data,
user, groups, security, application, and other networking functions.

6. Mobile OS:

Shivali Kumari 2237750 Page 2


Department of Information Technology

Mobile operating systems are those OS which is especially that are designed to power
smartphones, tablets, and wearables devices. Some most famous mobile operating systems are
Android and iOS, but others include BlackBerry, Web etc.

Functions of Operating System:

 Processor Management: An operating system manages the processor’s work by allocating


various jobs to it.
 Memory Management: An operating system manages the allocation and deallocation of the
memory to various processes.
 Device Management: There are various input and output devices. An OS controls the
working of these input-output devices.
 File Management: An operating system keeps track of information regarding the creation,
deletion, transfer, copy, and storage of files in an organized way.
 Security: The operating system provides various techniques which assure the integrity and
confidentiality of user data.
 Error Detection: From time to time, the operating system checks the system for any
external threat or malicious software activity. It also checks the hardware for any type of
damage.
 Job Scheduling: In a multitasking OS where multiple programs run simultaneously, the
operating system determines which applications should run in which order and how time
should be allocated to each application. 

Advantages of Operating System:

 Allows you to hide details of hardware by creating an abstraction


 Easy to use with a GUI
 Offers an environment in which a user may execute programs/applications
 The operating system must make sure that the computer system convenient to use
 Operating System acts as an intermediary among applications and the hardware
components
 It provides the computer system resources with easy to use format
 Acts as an intermediator between all hardware’s and software’s of the system

Shivali Kumari 2237750 Page 3


Department of Information Technology

Task No:- 1.a

Aim: Installation of Microsoft Windows Operating System.

Theory: Windows is a graphical operating system developed by Microsoft. It allows users to


view and store files, run the software, play games, watch videos, and provides a way to connect to
the internet. It was released for both home computing and professional works.

Procedure: Installing Windows 10

System requirement for Windows 10

• 1 GHz or faster processor or System on a Chip (SoC)

• 1 GB for 32-bit or 2 GB for 64-bit OS

• 16 GB for 32-bit OS or 32 GB for 64-bit OS (HDD)

• Bootable Media (USB / DVD)

• Internet connection (optional)

Steps Involves:

1. Download Windows 10
Go to https://www.microsoft.com/en-us/software-download/windows10%20.
This is the official download site for Windows 10. See figure 1.a.1 given below.

Figure 1.a.1- Download Windows 10

Shivali Kumari 2237750 Page 4


Department of Information Technology

2. Click Download tool now, this is a blue button in the middle of the page. This downloads
the Media Creation Tool, which you’ll use to create your installation media

Figure 1.a.2

3. Connect a blank USB flash drive or Insert a blank writeable DVD.


You can install Windows 10 by creating a bootable USB flash drive or DVD that contains
the Windows 10 installation files. You’ll need a USB flash drive that’s at least 8 GB or any
blank DVD to get started.

Figure 1.a.3

4. Double-click the download file. Its name begins with “MediaCreationTool” and ends with
“.exe”. You’ll find it in your default download folder, which is usually called Downloads. •
Click Yes when prompted to allow the installer to run.

Figure 1.a.4

Shivali Kumari 2237750 Page 5


Department of Information Technology

5. Click Accept button to accept the license. It’s in the bottom-right corner of the window

Figure 1.a.5

6. Select “create installation media” and click Next button. this option lets you create a
Windows installation disc or drive that will work on any compatible PC, not just the one
you’re using now.

Figure 1.a.6

7. Select your preferences and click Next button. If you are installing Windows on the
current PC, you can keep the default options. If you need to install on different PC, make
sure you choose the language and edition for which you have license, and select
architecture (64-bit or 32-bit) that matches the PC you’re going to install on.
• If you’re not sure about the architecture, you can choose Both from the menu.

Shivali Kumari 2237750 Page 6


Department of Information Technology

Figure 1.a.7

8. Choose an installation type and click Next button. An ISO file is a type of file that can be
burned to a DVD, so choose that option if you plan to create a DVD. Otherwise, choose
the USB flash drive option.

Figure 1.a.8

9. Create your installation media. The steps are a little different depending on what you’re
doing.
• Flash drive: Select your flash drive from the list, click Next, and wait for the
installation file to install. When the process is complete, click Finish.
• DVD/ISO: Click Save to the ISO file to your computer- it may take a while the file
is large and has to be downloaded. Once downloaded, you’ll see a progress screen
that monitors the download. When the download is complete, click Open DVD
burner on the “Burn the ISO file to a DVD” screen, select your DVD burner, and
then click Burn to create your DVD.

Shivali Kumari 2237750 Page 7


Department of Information Technology

Figure 1.a.9

10. Connect your Windows 10 installation media. If you created a flash drive, connect it to the
PC on which you want to install Windows 10. If you made a DVD, insert it into the driver
now.

Figure 1.a.10

11. Boot the PC into the BIOS. If your PC is not already set up to boot from your flash or
optical drive, rebooting from your installation media won’t work. You’ll need to make a
quick change in your BIOS to change the boot order. There are a few ways to get in:
• Windows 10: From Windows, open Settings, select Update & Recovery or
Update & Security, and go to Recovery > Restart now > Troubleshoot >
Advanced Option > UEFI Firmware Settings > Restart.
• Any PC: Reboot the PC and Immediately start pressing (over and over again)
the keyboard key required by your PC to enter “Setup” or BIOS. The key varies
by computer, but here are some of the most common keys:

Shivali Kumari 2237750 Page 8


Department of Information Technology

➢ Acer and Asus: F2 or Del


➢ Dell: F2 or F12
➢ HP: Esc or F10
➢ Lenovo: F1, F2 or Fn + F2
➢ Lenovo ThinkPad: Enter + F1

Figure 1.a.11

12. Go to the Boot tab. you’ll use the arrow keys to select it.
• The Boot tab may instead say Boot Order or Boot Option, depending on your
computer’s manufacturer.

Figure 1.a.12

13. Select a device from which to boot. you have a couple of options hare: • For a USB
flash drive, select the Removable Device option. • For a disc installation, select the
CD_ROM drive or Optical drive option.

Shivali Kumari 2237750 Page 9


Department of Information Technology

Figure 1.a.13

14. Press the +key until your boot option is first. Once either Removable device or CD_ROM
drive is at the top of the list, your computer will select your choice as its default boot
option.
 On some computers, you’ll instead press one of the function keys (eg, F5 or)
the arrow keys to navigate an option up to the top of the menu. The key will
be listed on the right side of the screen.

Figure 1.a.14

15. Save your settings. You should see a key prompt (eg, F10) at the bottom of the screen
that correlates to “Save and Exit”. Pressing it will save your settings and restart your
computer.

Shivali Kumari 2237750 Page 10


Department of Information Technology

Figure 1.a.15

16. Wait for your computer to restart. Once your computer finishes restarting, you’ll see
a window here with your geographical data. you’re now ready to begin setting up your
Windows 10 installation.

Figure 1.a.16

17. Next button when prompted. You can also change the options on this page (like
language, rime and currency, keyboard) before continuing if needed.

Figure 1.a.17

Shivali Kumari 2237750 Page 11


Department of Information Technology

18. Click Install Now button. It’s in the middle of the window.

Figure 1.a.18

19. Once you hit Install Now the setup will start gathering hardware information and it
will automatically take you to the next level.

Figure 1.a.19

20. Now on next window it will ask you for your CD key. Enter the CD key you have
bought from the Microsoft. You can use the on-screen keyboard or normal keyboard.

Figure 1.a.20

Shivali Kumari 2237750 Page 12


Department of Information Technology

21. Now accept the Terms and Condition from Microsoft and hit Next.

Figure 1.a.21

22. Now choose an option suitable for you. You can upgrade a previously installed
windows or custom install from the scratch. Here, I’m selecting Custom Installation.

Figure 1.a.22

23. Now after you select Custom installation you will land on a window called as
Partitioning window. Here you can create different Local disk partitions of your HDD
drive or you can select the partition containing the previous windows by formatting
that disk first.

Figure 1.a.23

Shivali Kumari 2237750 Page 13


Department of Information Technology

24. Once you are done with your partitioning hit Next and your window will start
installing. After it finishes up the window will ask for reboot. Reboot the window and
remove your bootable device before windows boot again after process finishes up to
getting file ready.

Figure 1.a.24

25. Once you are required to perform boot again of your computer. When your PC starts
back on, you need to select the settings. It is suggested that you choose Customize if
you don’t want to change the settings do later manually.

Figure 1.a.25

Shivali Kumari 2237750 Page 14


Department of Information Technology

26. Sign in with your account now. Then hit Next to continue.

Figure 1.a.26

27. The rest of the procedures are quite simple, and you should have no problem follow
through (like setting local account, network setting). this will be your last step after
that your window will be shown as below.

Figure 1.a.27

Result: Windows 10 is successfully installed in computer system

Shivali Kumari 2237750 Page 15


Department of Information Technology

Task No:- 1.b


Aim: Installation of Ubuntu Linux Operating System.

Theory: Ubuntu is a Linux-based operating system. It is designed for computers, smartphones,


and network servers. The system is developed by a UK based company called Canonical Ltd. All
the principles used to develop the Ubuntu software are based on the principles of Open Source
software development.

System requirement:

 2 GHz dual-core processor or better


 4 GB system memory
 25 GB of free hard drive space
 Internet access is helpful
 Either a DVD drive or a USB port for the installer media

Steps for installing Linux (Ubuntu): -

1. Download the Ubuntu image: Ubuntu is available for free from the Ubuntu website. It is
downloaded in ISO format, which needs to be burned to a CD or DVD before you can use it. Most
newer computers (built after 2011) will use the 64-bit version, while older computers will need the
32-bit version.
2. Burn the image to a disc: There are a variety of free image burning programs available, and
Windows 7, 8 and Mac OS X all have image burning capabilities built-in.
 In Windows 7 and 8, navigate to the downloaded ISO file and double-click on it. Insert a
blank disc into your burner, and follow the on-screen instructions to burn the disc.

Figure 1.b.1-Burn disc

Shivali Kumari 2237750 Page 16


Department of Information Technology

 In Mac OS X, open the Disk Utility. This is located in the Utilities folder, in your
Applications folder. Insert your blank disc into your disc drive. Drag and drop the ISO file
into the left frame of Disk Utility. Select the ISO file in the frame and click Burn.

Figure 1.b.2-Select ISO file and Burn

3. Set your computer to boot from the CD/DVD drive: In order to install Ubuntu, you will need to set
your computer to boot from discs. This is because the installation has to occur before your existing
operating system is loaded from the hard disk.
 When you reboot your computer, press the BIOS setup key to enter your BIOS menu. In
the Boot section, select your CD/DVD drive as the primary boot device. Once you have it
set, save and exit the BIOS. Your computer will reset again.

Figure 1.b.3- Boot from CD/DVD

 In Windows 8, hold the Shift key while clicking Restart in the Power menu. This will
reboot the computer into the Advanced Startup Options. From here, you can choose to boot
from a CD or DVD.

Shivali Kumari 2237750 Page 17


Department of Information Technology

Figure 1.b.4- Troubleshoot

4. Try Ubuntu before you install: If you’d like to take Ubuntu for a test drive before you commit to
installing it, you can run Ubuntu directly from the installation CD without making any changes to
your computer. Click the Try Ubuntu button to test it out.

Figure 1.b.5- Try Ubuntu

5. Start the installation process: Click the Install Ubuntu button to begin the installation. If you are
trying out Ubuntu before installing, you can start the installation by opening the Install file on the
test desktop.

Shivali Kumari 2237750 Page 18


Department of Information Technology
Figure 1.b.6- Install Ubuntu
6. You will need around 5 GB of free space on your computer to install Ubuntu.

Figure 1.b.7- Free space required

 Installation works best if you are connected to the internet. The easiest way to do this is to
plug an Ethernet cable directly into your computer from the router.

Figure 1.b.8- Connect internet

 You can also connect to a wireless network if Ubuntu recognizes your wireless adapter.

Figure 1.b.9- Connect to wireless network

Shivali Kumari 2237750 Page 19


Department of Information Technology

7. Check the boxes in the Preparing to install Ubuntu window: Ubuntu can automatically download
updates during the installation, and can install software that will allow you to play MP3 files and
Flash video (YouTube). Installing these updates and software during installation will save you a
significant amount of time and headaches when the operating system is installed.

Figure 1.b.10- Download updates

8. Choose your installation type: You can choose to install Ubuntu alongside your existing operating
system, you can replace your existing operating system, or you can create new partitions yourself.
If you choose to install alongside your existing operating system, you will be given the option to
set how much space is allocated for each operating system.

 If your computer doesn’t have an operating system installed yet, you will need to select
“Something else” and create a partition to install Ubuntu on. Make sure that the partition is
formatted as Ext4.

Figure 1.b.11-Installation Type

 If you install Ubuntu alongside your existing operating system, you will be given the option
to choose your operating system every time your computer is rebooted

Shivali Kumari 2237750 Page 20


Department of Information Technology

Figure 1.b.12-Select Installation Type

 If you replace your existing operating system with Ubuntu, you will lose all of your files
and programs. Make sure that you have everything backed up that you want to save.

Figure 1.b.13-Select Replace

9. Select your user options: Ubuntu will ask for your location in order to set the correct timezone. If
you are connected to the internet, this should happen automatically. You will also need to select
your keyboard layout, which is typically automatically picked for you.

Figure 1.b.14-Select Keyboard Layout

Shivali Kumari 2237750 Page 21


Department of Information Technology

10. Select a username and password: In the “Who are you?” window, you will need to enter your name,
your computer’s name, and a username and password that you will use to log in. You will need the
password when making administrative changes to the computer as well.

Figure 1.b.15-Select Username and password

11. Wait for the installation to complete. Once you have set your options, Ubuntu will begin to install.
This can take 30 minutes or more depending on your computer’s speed. Tips for using Ubuntu will
be displayed above the progress bar. Once the installation is complete, you will be prompted to
reboot your computer. Ubuntu is ready to use.

 If you have multiple operating systems installed, you will be given the option to choose
the one you want to load when your computer starts.

Figure 1.b.16-Wait for installation

Shivali Kumari 2237750 Page 22


Department of Information Technology

Figure 1.b.17-Select Operating system

 If you don’t have any other operating systems installed, Ubuntu will begin automatically

Figure 1.b.18-Ubuntu will begin

Shivali Kumari 2237750 Page 23


Department of Information Technology

Task No.- 2
AIM: Virtualization, Installation of Virtual Machine Software and Installation
of Operating System on Virtual Machine.

Introduction
Virtual Box allows you to run an entire operating system inside another operating system. Please be
aware that you should have a minimum of 512 MB of RAM. 1 GB of RAM or more is
recommended.

Comparison to Dual-Boot
Many websites (including the one you're reading) have tutorials on setting up dual- boots between
Windows and Ubuntu. A dual-boot allows you, at boot time, to decide which operating system you
want to use. Installing Ubuntu on a virtual machine inside of Windows has a lot advantages over a
dual-boot (but also a few disadvantages).

Advantages of virtual installation

 The size of the installation doesn't have to be predetermined. It can be a dynamically resized
virtual hard drive.
 You do not need to reboot in order to switch between Ubuntu and Windows.

 The virtual machine will use your Windows internet connection, so you don't have to worry
about Ubuntu not detecting your wireless card, if you have one.
 The virtual machine will set up its own video configuration, so you don't have to worry about
installing proprietary graphics drivers to get a reasonable screen resolution.
 You always have Windows to fall back on in case there are any problems. All you have to do
is press the right Control key instead of rebooting your entire computer.
 For troubleshooting purposes, you can easily take screenshots of any part of Ubuntu
(including the boot menu or the login screen).
 It's low commitment. If you later decide you don't like Ubuntu, all you have to do is delete the
virtual hard drive and uninstall Virtual Box.

Shivali Kumari 2237750 Page 24


Department of Information Technology

Disadvantages of virtual installation

 In order to get any kind of decent performance, you need at least 512 MB of RAM, because you
are running an entire operating system (Ubuntu) inside another entire operating system
(Windows). The more memory, the better. I would recommend at least 1 GB of RAM.
 Even though the low commitment factor can seem like an advantage at first, if you later decide
you want to switch to Ubuntu and ditch Windows completely, you cannot simply delete your
Windows partition. You would have to find some way to migrate out your settings from the
virtual machine and then install Ubuntu over Windows outside the virtual machine.
 Every time you want to use Ubuntu, you have to wait for two boot times (the time it takes to
boot Windows, and then the time it takes to boot Ubuntu within Windows).

Installation Process

Step 1: The first thing we have to do is to install oracle VirtualBox.

We can download the latest version of VirtualBox from the Virtual Box website:
https://www.virtualbox.org/wiki/Downloads . Go to DOWNLOAD folder at your
desktop. Run the VirtualBox-4.3.16-95972-Win.exe file. Oracle VM Virtual Box
Installation Window will appear.

Figure 2.1 Installation Window

Step 1.1: Click Next

Shivali Kumari 2237750 Page 25


Department of Information Technology

Figure 2.2 Click Next

Step 1.2: Uncheck “Create a shortcut in the Quick Launch Bar” and click “Next”

Figure 2.3 Create shortcut & Click Next

Step 1.3: Click “Yes”

Figure 2.4 Click Yes

Step 1.4: Click “Install”

Figure 2.5 Click Install

Shivali Kumari 2237750 Page 26


Department of Information Technology

Figure 2.6 Click Install

Figure 2.7 Click Install

Step 1.5: Click “Finish”

Figure 2.8 Click Finish

Step 1.6: After completion of Installation process, the Virtual Box Window gets opened

Figure 2.9 Virtual Box Window

Step 2: Get Ubuntu disk image (.iso file). After you launch VirtualBox from the Windows Start
menu, click on New to create a new virtual machine. When the New Virtual Machine Wizard
appears, click Next.

Shivali Kumari 2237750 Page 27


Department of Information Technology

Figure 2.10 Virtual Box Window

Step 3: You can call the machine whatever you want. If you're installing Ubuntu, it makes sense
to call it Ubuntu, I guess. You should also specify that the operating system is Linux.

Figure 2.11 Specify OS

Step 4: VirtualBox will try to guess how much of your memory (or RAM) to allocate for the
virtual machine. If you have 1 GB or less of RAM, I would advise you stick with the
recommendation. If, however, you have over 1 GB, about a quarter your RAM or less
should be fine. For example, if you have 2 GB of RAM, 512 MB is fine to allocate. If you
have 4 GB of RAM, 1 GB is fine to allocate. If you have no idea what RAM is or how
much of it you have, just go with the default. Click Next.

Figure 2.12 Allocate memory

Step 5: If this is your first time using VirtualBox (which it probably is if you need a tutorial on
Shivali Kumari 2237750 Page 28
Department of Information Technology

how to use it), then you do want to Create new hard disk and then click Next.

Figure 2.13 Create new hard disk

Step 6: Click Next again

Figure 2.14 Click Next

Step 7: Theoretically, a dynamically expanding virtual hard drive is best, because it'll take up only
what you actually use. I have come upon weird situations, though, when installing new
software in a virtualized Ubuntu, in which the virtual hard drive just fills up instead of
expanding. So I would actually recommend picking a Fixed-size storage.

Figure 2.14 Pick Fixed size Storage

Step 8: Ubuntu's default installation is less than 3 GB. If you plan on adding software or
downloading large files in your virtualized Ubuntu, you should tack on some buffer.

Shivali Kumari 2237750 Page 29


Department of Information Technology

Figure 2.14 Location and Size

Step 9: Click Create and wait for the virtual hard drive to be created. This is actually just a very
large file that lives inside of your Windows installation.

Figure 2.15 Click Create

Figure 2.16 Creating medium

Step 10: The next thing to do to make the (currently blank) virtual hard drive useful is to add the
downloaded Ubuntu disk image (the .iso) boot on virtual machine. Click on Settings and
Storage. Then, under CD/DVD Device, next to Empty, you'll see a little folder icon.
Click that.

Figure 2.17 Add iso file

Step 11: Select the Ubuntu .iso you downloaded earlier.

Shivali Kumari 2237750 Page 30


Department of Information Technology

Figure 2.18 Select .iso file

Step 12: Once you've selected it, click OK. Then double-click your virtual machine to start it
up.

Figure 2.19 Select .iso file

Step 13: You may get a bunch of random warnings/instructions about how to operate the guest
operating system within VirtualBox. Read those, and then you may also want to mark not
to see those again.

Figure 2.20 Click Ok

Shivali Kumari 2237750 Page 31


Department of Information Technology

Step 14: Wait for Ubuntu to boot up.

Figure 2.21 Booting up

Step 15: Once it's started up, just follow the regular installation procedure as if you were
installing.

Shivali Kumari 2237750 Page 32


Department of Information Technology

Task No.- 3
Aim: Implementation of CPU scheduling algorithms to find turnaround time and waiting time

Theory: CPU Scheduling is a process of determining which process will own CPU for
execution while another process is on hold. The main task of CPU scheduling is to make sure
that whenever the CPU remains idle, the OS at least select one of the processes available in the
ready queue for execution. The selection process will be carried out by the CPU scheduler. It
selects one of the processes in memory that are ready for execution.

There are various algorithms which are used by the Operating System to schedule the processes on
the processor in an efficient way.

The Purpose of a Scheduling algorithm:-

 Maximum CPU utilization

 Fare allocation of CPU

 Maximum throughput

 Minimum turnaround time

 Minimum waiting time

 Minimum response time

Types of CPU scheduling Algorithm

There are mainly six types of process scheduling algorithms

1. First Come First Serve (FCFS)


2. Shortest-Job-First (SJF) Scheduling
3. Shortest Remaining Time
4. Priority Scheduling
5. Round Robin Scheduling
6. Multilevel Queue Scheduling

1. First Come First Serve

It is the simplest algorithm to implement. The process with the minimal arrival time will get
the CPU first. The lesser the arrival time, the sooner will the process gets the CPU. It is the
non-preemptive type of scheduling.

Shivali Kumari 2237750 Page 33


Department of Information Technology

2. Shortest Job First Scheduling

The job with the shortest burst time will get the CPU first. The lesser the burst time, the
sooner will the process get the CPU. It is the non-preemptive type of scheduling.

3. Shortest Remaining Time Scheduling

It is the preemptive form of SJF. In this algorithm, the OS schedules the Job according to the
remaining time of the execution.

4. Priority based scheduling

In this algorithm, the priority will be assigned to each of the processes. The higher the
priority, the sooner will the process get the CPU. If the priority of the two processes is same
then they will be scheduled according to their arrival time.

5. Round Robin Scheduling

In the Round Robin scheduling algorithm, the OS defines a time quantum (slice). All the
processes will get executed in the cyclic way. Each of the process will get the CPU for a
small amount of time (called time quantum) and then get back to the ready queue to wait for
its next turn. It is a preemptive type of scheduling.

6. Multilevel Queue Scheduling


This algorithm separates the ready queue into various separate queues. In this method,
processes are assigned to a queue based on a specific property of the process, like the
process priority, size of the memory, etc. However, this is not an independent scheduling OS
algorithm as it needs to use other types of algorithms in order to schedule the jobs.

Important CPU scheduling Terminologies :-

 Arrival Time (AT)- The time when the process arrives into the running state is called as the
arrival time of the process. In simple words, the time at which any process enter the CPU is
known as the arrival time.

Shivali Kumari 2237750 Page 34


Department of Information Technology

 Completion Time (CT)- The time when the Process is done with all its execution and it
enters the termination state is called as the completion time of the process. It can be also
defined as the time when a process ends.

 Burst Time (BT)- The time for which the process needs to be in the running state is known as
the burst time of the process. We can also define it as the time which a process requires for
execution is the Burst time of the process.

 Turn Around Time (TAT)- Turn Around time can be defined as the total time the process
remains in the main memory of the system. The Ready state, Waiting for state and the
Running State, together make up the main memory of the system. So, the time for which the
process remains in these states is known as the Turn Around Time of the process. In simple
words, it is the time that a process spends after entering the ready state and before entering the
termination state.

It can be calculated as follows:

Turn Around Time = Completion Time – Arrival Time


TAT = CT - AT

 Waiting Time (WT)- The time for which a process waits for going into the running state.
It is the sum of the time spent by the process in the ready state and the waiting state.
Another way of calculating it is as follows:

Waiting Time= Turn Around Time – Burst Time


WT = TAT – BT

Shivali Kumari 2237750 Page 35


Department of Information Technology

Task No.- 3.a


Aim: First Come First Serve (FCFS).

Theory: First Come First Serve (FCFS) is an operating system scheduling algorithm that
automatically executes queued requests and processes in order of their arrival. It is the easiest and
simplest CPU scheduling algorithm. In this type of algorithm, processes which requests the CPU
first get the CPU allocation first. This is managed with a FIFO queue. 

As the process enters the ready queue, its PCB (Process Control Block) is linked with the tail of
the queue and, when the CPU becomes free, it should be assigned to the process at the beginning
of the queue.

Characteristics of FCFS :-

 It supports non-pre-emptive and pre-emptive scheduling algorithm.


 Jobs are always executed on a first-come, first-serve basis.
 It is easy to implement and use.
 This method is poor in performance, and the general wait time is quite high.

Implementation of FCFS :-

#include<iostream>

using namespace std;

int main()

int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;

cout<<"Shivali Kumari 2237750 IT-C1 4th Sem"<<endl;

cout<<"\n Enter total number of processes(maximum 20):";

cin>>n;

cout<<"\n Enter Process Burst Time aka DURATION \n";

for(i=0;i<n;i++)

Shivali Kumari 2237750 Page 36


Department of Information Technology

cout<<"P["<<i+1<<"]:";

cin>>bt[i];

wt[0]=0; //waiting time for first process is 0

for(i=1;i<n;i++) //calculating waiting time

wt[i]=0;

for(j=0;j<i;j++)

wt[i]+=bt[j];

cout<<"\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time";

for(i=0;i<n;i++) //calculating turnaround time

tat[i]=bt[i]+wt[i];

avwt+=wt[i];

avtat+=tat[i];

cout<<"\nP["<<i+1<<"]"<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\t"<<tat[i];

avwt/=i;

avtat/=i;

cout<<"\n\n Average Waiting Time:"<<avwt;

cout<<"\n Average Turnaround Time:"<<avtat;

return 0;

Shivali Kumari 2237750 Page 37


Department of Information Technology

Output:-

Shivali Kumari 2237750 Page 38


Department of Information Technology

Task No.- 3.b


Aim: Implementation of CPU scheduling algorithms to find turnaround time and waiting time for
Shortest Job First ( SJF ).

Theory: To calculate the average waiting time in the shortest job first algorithm the sorting of the
process based on their burst time in ascending order then calculate the waiting time of each
process as the sum of the bursting times of all the process previous or before to that process.

Example:
Process ID Brust Time Waiting Time Turnaround
Time
A 9 11 20
B 5 2 7
C 2 0 2
D 15 20 35
E 7 7 14
Average = 8 Average = 15.6
Gantt Chart
C B E A D
0 2 7 11 20 35
Code:
#include<iostream>
using namespace std;
int main()
{
int n, p[20], bt[20], wt[20], tat[20], avwt=0, avtat=0, i ,j;
cout<<"Shivali Kumari 2237750 IT-C1 4th Sem"<<endl;
cout<<"Enter the number of process: ";
cin>>n;
cout<<"Enter process burst time::"<<endl;
for(i=0; i<n; i++)
{
cout<<"process"<<i+1<<"::";
cin>>bt[i];
p[i]=i+1;
}
for(int i=0; i<n; i++)
{

Shivali Kumari 2237750 Page 39


Department of Information Technology

for(int j=i+i; j<n; j++)


{
if (bt[j]<bt[i])
swap(bt[i],bt[j]);
swap(p[i],p[j]);
}
}
wt[0]=0;
for(i=1; i<n; i++)
{
wt[i]=0;
for(j=0; j<1; j++)
{
wt[i]+=bt[i];
}
}
cout<<"process \t burst time \t waiting time \t turnaround time"<<endl;
for(i=0; i<n; i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
cout<<p[i]<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\t"<<tat[i]<<endl;
}
avwt/=i;
avtat/=i;
cout<<"average waiting time:"<<avwt<<endl;
cout<<"average turnaround time:"<<avtat<<endl;
return 0;
}

Shivali Kumari 2237750 Page 40


Department of Information Technology

Output:-

Figure 3.b.1 Output(SJF)

Task No.- 3.c

Shivali Kumari 2237750 Page 41


Department of Information Technology

Aim: Implementation of CPU scheduling algorithms to find turnaround time and waiting time for
Round Robin (pre-emptive).

Theory: Round Robin scheduling algorithm is one of the most popular scheduling algorithm
which can actually be implemented in most of the operating systems. This is the pre-emptive
version of first come first serve scheduling. The Algorithm focuses on Time Sharing. In this
algorithm, every process gets executed in a cyclic way. A certain time slice is defined in the
system which is called time quantum. Each process present inthe ready queue is assigned the
CPU for that time quantum, if the execution of the process is completed during that time then the
process will terminate else the process will go back to the ready queue and waits for the next turn
to complete the execution.

Example:
Process ID Burst Time Waiting Time Turnaround Time
A 6 8 14
B 4 6 10
C 8 10 18
Average = 8 Average = 14
Gantt Chart
A B C A B C A C C
0 2 4 6 8 10 12 14 16 18

Code:-

#include<iostream>

using namespace std;

void findWaitingTime (int processes[], int n, int bt[], int wt[], int quantum)

int rem_bt[n];

for (int i = 0; i < n; i++)

rem_bt[i] = bt[i];

int t = 0;

Shivali Kumari 2237750 Page 42


Department of Information Technology

while (1)

bool done = true;

for (int i = 0; i < n; i++)

if (rem_bt[i] > 0)

done = false;

if (rem_bt[i] > quantum)

t += quantum;

rem_bt[i] -= quantum;

else

t = t + rem_bt[i];

wt[i] = t - bt[i];

rem_bt[i] = 0;

Shivali Kumari 2237750 Page 43


Department of Information Technology

if (done == true) break;

void findTurnAroundTime (int processes[], int n, int bt[], int wt[], int tat[])

for (int i = 0; i < n; i++)

tat[i] = bt[i] + wt[i];

void findavgTime (int processes[], int n, int bt[], int quantum)

int wt[n], tat[n], total_wt = 0, total_tat = 0;

findWaitingTime (processes, n, bt, wt, quantum);

findTurnAroundTime (processes, n, bt, wt, tat);

cout << "Processes " << " Burst time " <<" Waiting time " << " Turn around time\
n";

for (int i = 0; i < n; i++)

total_wt = total_wt + wt[i];

total_tat = total_tat + tat[i];

cout << " " << i +1 << "\t\t" << bt[i] << "\t " << wt[i] << "\t\t " << tat[i] << endl;

Shivali Kumari 2237750 Page 44


Department of Information Technology

cout << "Average waiting time = " << (float) total_wt / (float) n; cout << "\
nAverage turn around time = " << (float) total_tat / (float) n;

int main ()

int processes[] = { 1, 2, 3, 4 };

int n = sizeof processes / sizeof processes[0];

int burst_time[] = { 7, 4, 3, 4 };

int quantum = 2;

cout<<"Shivali Kumari 2237750 IT-C1 4TH Sem\n";

cout << "Quantum=" << quantum << "\n";

findavgTime (processes, n, burst_time, quantum);

return 0;

Output:-
Shivali Kumari 2237750 Page 45
Department of Information Technology

Figure 3.c.1 Output( RR )

Task No.- 3.d


Aim: Implementation of CPU scheduling algorithms to find turnaround time and waiting time for
Priority Scheduling.

Shivali Kumari 2237750 Page 46


Department of Information Technology

Theory: To calculate the average waiting time in the priority algorithm, sort the burst times
according to their priorities and then calculate the average waiting time of the processes. The
waiting time of each process is obtained by summing up the burst times of all the previous
processes.
Example:
Process Id Burst Time Priority Waiting Time Turnaround Time
A 5 3 9 14
B 2 1 0 2
C 9 4 14 23
D 7 2 2 9
Average = 6.25 Average = 12

Gantt Chart:
B D A C
0 2 9 14 23

Code:-

#include<bits/stdc++.h>

using namespace std;

int main()

cout<<"Shivali Kumari 2237750 IT-C1 4TH Sem"<<endl;

int n;

float avg1=0;

float avg2=0;

cout<<"Enter number of processes\n";

cin>>n;

vector<tuple<int,int,int> > input(n);

int i;

int x,y,z;

for(i=0; i<n; i++)

Shivali Kumari 2237750 Page 47


Department of Information Technology

{ x=i+1;

cout<<"Enter burst time of process: "<<i+1<<endl;

cin>>y;

cout<<"Enter priority of this process "<<endl;

cin>>z;

input[i]=make_tuple(z,x,y);

sort(input.begin(),input.end());

int w[n];

int t[n];

int sum=0;

for(i=0;i<n;i++)

w[i]=sum;

sum+=get<2>(input[i]);

for(i=0;i<n;i++)

t[i]=w[i]+get<2>(input[i]);

avg1+=w[i];

avg2+=t[i]; }

cout<<"Process No Burst Time Priority Waiting Time Turnaround Time \n";

for(i=0;i<n;i++)

Shivali Kumari 2237750 Page 48


Department of Information Technology

cout<<get<1>(input[i])<<"\t\t"<<get<2>(input[i])<<"\t\t"<<get<0>(input[i])<<"\t\t"<<w[i]<<"\t \
t"<<t[i]<<endl;

cout<<"average waiting time : "<<avg1/(float)(n)<<endl;

cout<<"average turnaround time : "<<avg2/(float)(n)<<endl;

return 0;

Output:-

Figure 3.d.1 Output(Priority)

Task No.- 4.a


Aim: Commands for files & directories: cd, ls, cp, md, rm, mkdir, rmdir
Creating and viewing files using cat , File comparisons

Shivali Kumari 2237750 Page 49


Department of Information Technology

Theory: In this article we discuss Linux commands used to manage directories and perform
operations such as listing directories, printing the current working directory, creating and removing
a directory, copying a directory, moving a directory from its current location to another or renaming
the directory.

• To study the commands for listing files and directory: cd, ls, cp, md, rm, mkdir, rmdir
Basically, ls means listing files .so files can be hidden, it can be long listing, or it can be existing files so
that’s why ls command can be used in many ways i.e Ls

I. Ls – a
II. Ls – l
III. Ls - a – l
IV. Ls d*

I. LS COMMAND: - This command is used for showing existing all files and directory ,whenever we
want to see saved files and directory we always use ls command for it shows file with different colours
like blue colour shows directories and while colour shows files.

II. LS – A COMMAND: - This command is used to listing out all hidden files. That’s why for viewing
hidden files we use ls- a command. Sometime we hide our file for preventing its viewing that’s why
to see hidden files we use this command.

III. LS- L COMMAND:- This command is used for viewing long listing files , it means it
shows a long list of many n.

IV. LS – A - L COMMAND :- This command is used to show both hidden files and long listing files.

Shivali Kumari 2237750 Page 50


Department of Information Technology

V. Ls d*: - this command list out all files which are saved by name starting with a letter. we can
also use another alphabet using same command inspite of writing any alphabet at place of d.

CD COMMAND:-

The cd (change directory) command is used to change the current working directory. This
command enables users to navigate through the system's directories.

The syntax is as follow.

cd [DIRNAME]

 To change from the current directory to another directory we write,

Cd home/user/Desktop

We could also write,

cd ~/Desktop

since the ~ character represents the home directory.

d.

• To change to another user's directory, we write,

Shivali Kumari 2237750 Page 51


Department of Information Technology

cd ~username

• We can also change into subdirectories as follows,

cd /home/user/Desktop/files/

• We can also change directories as follows,

user:~$ cd Documents/Dir1/Dir2/Dir3

user:~/Documents/Dir1/Dir2/Dir3$ cd ..

user:~/Documents/Dir1/Dir2$ cd ..

user:~/Documents/Dir1$ cd ..

user:~/Documents$

CP COMMAND: -

This command is used to copy file and directory. Whenever we want to copy content of one file to
another then we use this command. The cp command makes a copy of a file for you.

For example: cp file footmarks an exact copy of the file whose name you entered and name the copy
too, but the first file will still exist with its original name. After you use mv, the original file no
longer exists, but after you use cp, that file stays and a new copy is made.

Cp [option (s)] source file


Target file: - Copies source file to target file

Syntax of command is: -

cp a b

Example:- cp a b

Shivali Kumari 2237750 Page 52


Department of Information Technology

This command means we are copying content of file a to file b.

mkdir COMMAND :-

The mkdir(make directory) command is used to create a new directory.

The syntax is as follows,

mkdir [DIRNAME]

• To create a single directory we write,

mkdir newDir

 To create multiple directories we write,

mkdir newDir1 newDir2 newDir2

• To print output of the command we use the -v option,

$ mkdir newDirmkdir: created directory 'newDir'

rmdir COMMAND: -
The rmdir(remove directory) command is used to delete an empty directory.
The syntax is as follows,

rmdir [DIRNAME]

To remove a non-empty directory, that is a directory with files and subdirectories we use
the rm -r dirname command.

mv COMMAND: -
The mv(move) command is used to move files and directories in Linux, it can also
be used to rename files and directories.

Shivali Kumari 2237750 Page 53


Department of Information Technology

The syntax is as follows,

mv [OLD] [NEW]

• To change the name of NewDir to ChangedDir we write,

mv newDir ChangedDir

• To move a directory/file we can write,

mv newDir ~/Documents/Dirs

This command will remove newDir from the current directory and move it to ~/Documents/Dirs.

Creating and viewing files using cat

Create test1.txt and test2.txt, which you can use as sample files to test out the other commands.
1. Open a terminal window and create the first file:

cat >test1.txt

2. The cursor moves to a new line where you can add the wanted text. Type a simple sentence
such as:

This is test file #1.

3. To exit the prompt and write the changes to the file, hold the Ctrl key and press d.

4. Repeat the process to create test2.txt. Run:

cat >test2.txt

5. Type:

This is test file #2.

Shivali Kumari 2237750 Page 54


Department of Information Technology

6. Press Ctrl+d.

File comparisons:

The file comparison command helps us to compare the files and find the similarities and
differences between these files. The different file comparison commands used in Unix are cmp,
comm, diff, dircmp, and uniq.

Different ways of comparing two files in Unix

#1) cmp: This command is used to compare two files character by character.

• Syntax: cmp [options] file1 file2


• Example: Add write permission for user, group and others for file1.
• $ cmp file1 file2
#2) comm: This command is used to compare two sorted files.

• Syntax: comm [options] file1 file2


• One set of options allows selection of ‘columns’ to suppress.
• -1: suppress lines unique to file1 (column 1)
• -2: suppress lines unique to file2 (column 2)
• -3: suppress lines common to file1 and file2 (column3)
• Example: Only show column-3 that contains lines common between file1 and file2
• $ comm -12 file1 file2
#3) diff: This command is used to compare two files line by line.

• Description: The output indicates how the lines in each file are different, and the steps
involved to change file1 to file2. The ‘patch’ command can be used to make the suggested
changes. The output is formatted as blocks of: Change commands.

< lines from file1

> lines from file2

The change commands are in the format [range][acd][range]. The range on the left may be a line
number or a comma-separated range of line numbers referring to file1, and the range on the right
similarly refers to file2. The character in the middle indicates the action i.e., add, change, or
delete.

• ‘LaR’ – Add lines in range ‘R’ from file2 after line ‘L’ in file1.
• ‘FcT’ – Change lines in range ‘F’ of file1 to lines in range ‘T’ of file2.

Shivali Kumari 2237750 Page 55


Department of Information Technology

• ‘RdL’ – Delete lines in range ‘R’ from file1 that would have appeared at line ‘L’ in
file2.
• Syntax: diff [options] file1 file2
• Example: Add write permission for user, group, and others for file1
• $ diff file1 file2
#4) dircmp: This command is used to compare the contents of directories.

• Description: This command works on older versions of Unix. In order to compare the
directories in the newer versions of Unix, we can use diff -r
• Syntax: dircmp [options] dir1 dir2
• Example: Compare contents of dir1 and dir2
$ dircmp dir1 dir2

Task No.- 4.b


Aim: Processes in Linux, connecting processes with pipes, Background processing,
Managing multiple processes

Shivali Kumari 2237750 Page 56


Department of Information Technology

Background process: changing process priority , scheduling of processes at command ,


batch commands, kill , ps , who , sleep.

Theory:

Processes in Linux
An instance of a program is called a Process. In simple terms, any command that you give to your
Linux machine starts a new process.

Types of Processes:

• Foreground Processes: They run on the screen and need input from the user.
For example, Office Programs
• Background Processes: They run in the background and usually do not need user input.
For example, Antivirus.

Connecting Proccesses with pipes:-


● A pipe is a form of redirection (transfer of standard output to some other destination) that is usedin
Linux and other Unix-like operating systems to send the output of one command/ program/
process to another command/program/process for further processing.

● The Unix/Linux systems allow stdout of a command to be connected to stdin of another


command. You can make it do so by using the pipe character ‘|’.

● Pipe is used to combine two or more commands, and in this, the output of one command acts as
an input to another command, and this command’s output may act as input to the next
command and so on.

Shivali Kumari 2237750 Page 57


Department of Information Technology

● It can also be visualized as a temporary connection between two or more commands/


programs/processes. The command line programs that do the further processing are referred to
as filters.

Syntax: command_1 | command_2 | | command_N

Example : 1. Listing all files and directories and give it as input to more command.

$ ls -l | more

Running a Background process:-


If you start a foreground program/process from the terminal, then you cannot work on the
terminal, till the program is up and running.

Particular, data-intensive tasks take lots of processing power and may even take hours to
complete. You do not want your terminal to be held up for such a long time.

To avoid such a situation, you can run the program and send it to the background so that
terminal remains available to you.

Let’s learn how to do this –

Fg
You can use the command “fg” to continue a program which was stopped and bring it to the foreground.

Shivali Kumari 2237750 Page 58


Department of Information Technology

The simple syntax for this utility is: fg jobname

Example:-

1. Launch ‘banshee’ music player


2. Stop it with the ‘ctrl +z’ command.
3. Continue it with the ‘fg’ utility.

Let’s look at other important commands to manage processes –


Top
This utility tells the user about all the running processes on the Linux machine

Press ‘q’ on the keyboard to move out of the process display.

The terminology follows:

Shivali Kumari 2237750 Page 59


Department of Information Technology

Field Description Example 1 Example 2

PID The process ID of each task 1525 961

User The username of task owner Home Root

Priority
PR 20 20
Can be 20(highest) or -20(lowest)
NI The nice value of a task 0 0

VIRT Virtual memory used (kb) 1775 75972

RES Physical memory used (kb) 100 51

SHR Shared memory used (kb) 28 7952

Field Description Example 1 Example 2

Status S R

There are five types:

‘D’ = uninterruptible sleep‘R’ =


running

‘S’ = sleeping

‘T’ = traced or stopped‘Z’ =


zombie

%CPU % of CPU time 1.7 1.0

%MEM Physical memory used 10 5.1


TIME+ Total CPU time 5:05.34 2:23.42

Photoshop
Command Command name Xorg.exe
PS
This command stands for ‘Process Status’. It is similar to the “Task Manager” that pop-ups in a
Windows Machine when we use Ctrl+Alt+Del. This command is similar to ‘top’ command, but the
information displayed is different.

Shivali Kumari 2237750 Page 60


Department of Information Technology

To check all the processes running under a user, use the command – ps ux

You can also check the process status of a single process, use the syntax – ps PID

Kill
This command terminates running processes on a Linux machine.

To use these utilities you need to know the PID (process id) of the process you want to kill

Syntax – kill PID

To find the PID of a process simply type pidof Process name

Let us try it with an example.

NICE
Linux can run a lot of processes at a time, which can slow down the speed of some high priority processes
and result in poor performance.

To avoid this, you can tell your machine to prioritize processes as per your requirements.

This priority is called Niceness in Linux, and it has a value between -20 to 19. The lower the Niceness index,
the higher would be a priority given to that task.

The default value of all the processes is 0.

To start a process with a niceness value other than the default value use the following syntax nice -n

'Nice value' process name

Shivali Kumari 2237750 Page 61


Department of Information Technology

If there is some process already running on the system, then you can ‘Renice’ its value using syntax.

renice 'nice value' -p 'PID'

To change Niceness, you can use the ‘top’ command to determine the PID (process id) and its Nice value.
Later use the renice command to change the value.
Let us understand this by an example.

DF
This utility reports the free disk space(Hard Disk) on all the file systems.

If you want the above information in a readable format, then use the command 'df -h'

Free
This command shows the free and used memory (RAM) on the Linux system.

Shivali Kumari 2237750 Page 62


Department of Information Technology

Who

The who command displays information about all users currently on the local system.

The following information is displayed: login name, try, date and time of login. Typing who am I or who am
I displays your login name, tty, date and time you logged in.

Task No.- 4.c

Shivali Kumari 2237750 Page 63


Department of Information Technology

Aim: Printing commands grep, fgrep, find, sort, cal, banner, touch file.
File related commands wc, sat, cut, grep.
Theory:

GREP Command: - This command is also very important command . GREP means globally
search a regular expression and print it . By using this command we can search single letter in file
and also can search through line content in a file.

Fig 4c.1 (grep command)

FGREP Command :- The fgrep filter is used to search for the fixed-character strings in a
file. There can be multiple files also to be searched. This command is useful when you need to
search for strings which contain lots of regular expression metacharacters, such as “^”,
“$”, etc.
Syntax: fgrep[options] [ -e pattern_list] [pattern] [file]

SORT Command :- This command is used to sort the details of a file accordingly.

This command is very important.

Shivali Kumari 2237750 Page 64


Department of Information Technology

Fig 4c.2 (sort command)

CAL Command :- This command is used to display calendar.

Fig 4c.3 (cal command)

Shivali Kumari 2237750 Page 65


Department of Information Technology

BANNER Command :- Banner command in linux is used to print the ASCII character string in
large letter to standard output.
Syntax : banner text

Example: banner 1234567890

Fig 4c.4 (banner command)

TOUCH Command :- The touch command allows users to make files using the Linux
CLI. Just as the mkdir command makes directories, the touch command makes files. Just as you would
make a .doc or a .txt using a PC desktop, the touch command makes empty files.

Syntax: - touch file_name touch

File1_name File2_name....n

An example of the touch command: - touch testfile.txt

The example touch command effectively created the file testfile.txt. As noted by the extension, the file
created is a .txt or text file. To equate, a .txt file in Linux is akin to a.txt notebook file within a Windows
or Mac OS.

Example: - touch a1 a2 a3

It means we can also create multiple files using this command. Here we created three different files a1, a2

and a3.

Shivali Kumari 2237750 Page 66


Department of Information Technology

Fig 4c.5 (touch command)

WC Command :- This command is used to display the number of lines, number of words, number
of bytes, and file name from the file 'exm.txt'.

Consider the below output:

Fig 4c.6 (wc command)

Here,

4 is number of lines.

16 is number of words.

80 is number of bytes.

Shivali Kumari 2237750 Page 67


Department of Information Technology

Task No.- 5.a

Aim:- Shell programming : Basic of shell programming, various types of shell.


Objective: To use ECHO command
To use read command
To solve arithmetic expression

SHELL:- Shell provide an environment where users can run its commands, programs, and
shell script.
The shell provides you with an interface to the UNIX system. It gathers input from you and
executes programs based on that input. When a program finishes executing, it displays that
program's output.
A shell is an environment in which we can run our commands, programs, and shell scripts. There
are different flavours of shells, just as there are different flavours of operating systems. Each
flavour of shell has its own set of recognized commands and functions.

SHELL SCRIPT:- A shell script is a computer program designed to be run by the Unix/Linux
shell which could be one of the following:

• The Bourne Shell


• The C Shell
• The Korn Shell
• The GNU Bourne-Again Shell

Shell Types:-

In UNIX there are two major types of shells:


The Bourne shell- If you are using a Bourne-type shell, the default prompt is the $ character.
The C shell- If you are using a C-type shell, the default prompt is the % character.

There are again various subcategories for Bourne Shell which are listed as follows:

 Bourne shell ( sh)


 Korn shell ( ksh)
 Bourne Again shell ( bash)
 POSIX shell ( sh)

A shell is a command-line interpreter and typical operations performed by shell scripts include file
manipulation, program execution, and printing text.

Shivali Kumari 2237750 Page 68


Department of Information Technology

Typical operations performed by shell scripts include file manipulation, program


execution, and printing text.

To use ECHO command:

ECHO:- This command is used when we want to display the content as it is written .This
command will displays entenceor word as is.
SYNTAX: - echo “.................”

Example:
To use read command

READ COMMAND:-. Read command in Linux system is used to read from a file
descriptor. Basically, this command read up the total number of bytes from the specified file
descriptor into the buffer. If the number or count is zero then this command may detect the
errors. But on success, it returns the number of bytes read

SYNTAX:-read data1 data2 data3


EXAMPLE:-
To solve arithmetic expression

ARITHMETIC COMMANDS:- It is very important to understand that all the conditional


expressions should be inside square braces with spaces around them, for example [ $a == $b ] is
correct whereas, [$a==$b] is incorrect.
SYNTAX:-val=expr$value1+$value2 $echo“…….”

Shivali Kumari 2237750 Page 69


Department of Information Technology

Task No.- 5.b

Aim:-Programming in bash, conditional & looping statement, case statements


,parameter passing and arguments.

The CASE statement is a powerful conditional statement in Bash that allows you to test a
variable against a list of values. It is a more concise and efficient alternative to using multiple
if-then statements. Many times it is a good alternative to if-else statements. You can also use
it for processing the command line arguments in a shell script.
The case statement tests the input value until it finds the corresponding pattern and executes
the command linked to that input value. Thus, it is an excellent choice for creating menus
where users select an option which triggers a corresponding action.

To study conditional statements, loops in shell

Objective:
• To perform arithmetic operation using expr.
• To execute conditional statement

o if [condition] then
statement
fi

o if [condition] then
statement else
fi

• To execute loops in shell using relational operator


While [condition] do
statement done

To execute conditional statement

Theory:

Shivali Kumari 2237750 Page 70


Department of Information Technology

• CONDITIONAL STATEMENT: Conditional statements are those whose outcome


depends upon some condition i.e. either they are true or false basically these statements are
if, else, else if etc. nested of these statements are true.

EXAMPLE: If[ condition] then statement

if [statement]
then statement
else
fi

• To execute loops in shell using relational operator

Shivali Kumari 2237750 Page 71


Department of Information Technology

While …….do…….done: While do then can also be implemented using relational operator.
Relational operators are like

 Equalto--- (-eq)
 Not equalto---(-ne)
 Greaterthan---(-gt)
 Greater than equal to---(-ge)
 Less than equal to---(-le)
 Lesser than (-lt)

Shivali Kumari 2237750 Page 72


Department of Information Technology

Parameter passing and arguments:-


There are different ways in which parameter data can be passed into and out of methods and
functions.
Let us assume that a function B() is called from another function A(). In this case A is called the
“caller function” and B is called the “called function or callee function”. Also, the
arguments which A sends to B are called actual arguments and the parameters of B are called
formal arguments. Terminology
• Formal Parameter : A variable and its type as they appear in the prototype of the
function or method.
• Actual Parameter : The variable or expression corresponding to a formal parameter
that appears in the function or method call in the calling environment.
• Modes:
• IN: Passes info from caller to callee.
• OUT: Callee writes values in caller.
• IN/OUT: Caller tells callee value of variable, which may be updated by callee.

Important methods of Parameter Passing


1. Pass By Value: This method uses in-mode semantics. Changes made to formal parameter
do not get transmitted back to the caller. Any modifications to the formal parameter
variable inside the called function or method affect only the separate storage location and
will not be reflected in the actual parameter in the calling environment. This method is
also called as call by value.

Shivali Kumari 2237750 Page 73


Department of Information Technology

// C program to illustrate call by value


#include <stdio.h>
void func(int a, int b)
{
a += b;
printf("In func, a = %d b = %d\n", a, b);
}
int main(void)
{
int x = 5, y = 7;
// Passing parameters
func(x, y);
printf("In main, x = %d y = %d\n", x, y);
return 0;
}

Pass by reference(aliasing): This technique uses in/out-mode semantics.


Changes made to formal parameter do get transmitted back to the caller through parameter
passing. Any changes to the formal parameter are reflected in the actual parameter in the
calling environment as formal parameter receives a reference (or pointer) to the actual data.
This method is also called as call by reference. This method is efficient in both time and
space.

Shivali Kumari 2237750 Page 74


Department of Information Technology

//C program to illustrate call by reference


#include <stdio.h>
void swapnum(int* i, int* j)
{
int temp = *i;
*i = *j;
*j = temp;
}
int main(void)
{
int a = 10, b = 20;
// passing parameters
swapnum(&a,&b);
printf("a is %d and b is %d\n", a, b);
return 0;
}

Task No.- 5.c

Aim:- Shell variables, shell keywords, creating shell programs for


automate systems tasks, report printing.

A variable is nothing more than a pointer to the actual data. The shell enables
you to create, assign, and delete variables.

Variable Names

Shivali Kumari 2237750 Page 75


Department of Information Technology

The name of a variable can contain only letters (a to z or A to Z), numbers ( 0 to


9) or the underscore character ( _).
By convention, Unix shell variables will have their names in
UPPERCASE.
The following examples are valid variable names −
_ALI
TOKEN_A
VAR_1
VAR_2
Following are the examples of invalid variable names −
2_VAR
-VARIABLE VAR1-
VAR2 VAR_A!

The reason you cannot use other characters such as !, *, or - is that these characters have a
special meaning for the shell.
AD

Defining Variables
Variables are defined as follows −
variable_name=variable_value
For example −
NAME="Zara Ali"

The above example defines the variable NAME and assigns the value "Zara Ali" to it.
Variables of this type are called scalar variables. A scalar variable can hold only one value at
a time.
Shell enables you to store any value you want in a variable. For example −
VAR1="Zara Ali"
VAR2=100

Accessing Values
To access the value stored in a variable, prefix its name with the dollar sign ($) −
For example, the following script will access the value of defined variable NAME and print
it on STDOUT −
Live Demo
#!/bin/sh

NAME="Zara Ali"
echo $NAME

Shivali Kumari 2237750 Page 76


Department of Information Technology

The above script will produce the following value −


Zara Ali
AD

Read-only Variables
Shell provides a way to mark variables as read-only by using the read-only command. After
a variable is marked read-only, its value cannot be changed.
For example, the following script generates an error while trying to change the value
of NAME −
Live Demo
#!/bin/sh

NAME="Zara Ali"readonly NAME


NAME="Qadiri"

The above script will generate the following result −


/bin/sh: NAME: This variable is read only.

Unsetting Variables
Unsetting or deleting a variable directs the shell to remove the variable from the list of
variables that it tracks. Once you unset a variable, you cannot access the stored value in the
variable.
Following is the syntax to unset a defined variable using the unset command −
unset variable_name
The above command unsets the value of a defined variable. Here is a simple example that
demonstrates how the command works −
#!/bin/sh

NAME="Zara Ali" unset NAME echo $NAME

The above example does not print anything. You cannot use the unset command to unset
variables that are marked readonly.

Variable Types
When a shell is running, three main types of variables are present −

 Local Variables − A local variable is a variable that is present within the current
instance of the shell. It is not available to programs that are started by the shell. They
are set at the command prompt.
 Environment Variables − An environment variable is available to any child process
of the shell. Some programs need environment variables in order to function correctly.
Usually, a shell script defines only those environment variables that are needed by the
programs that it runs.

Shivali Kumari 2237750 Page 77


Department of Information Technology

 Shell Variables − A shell variable is a special variable that is set by the shell and is
required by the shell in order to function correctly. Some of these variables are
environment variables whereas others are local variables.

Shell Keywords in Linux Programming


Keywords are the words whose meaning has already been explained to the shell.the
keywords cannot be used as variable names because of it is a reserved words with
containing reserved meaning.

echo read set unset

readonly shift export if

fi else while do

done for until case

esac break continue exit

return trap wait eval

exec ulimit umask

To customise a shell script, we first need to create it as follows:


1. To hold a text program, we need to create a text file.
2. Choose a shell to write the script.
3. Add the necessary commands to the file.
4. Save the file.
5. Change its permissions to make the file executable.
6. Run the shell program

Printing Files
Before you print a file on a UNIX system, you may want to reformat it to adjust the margins,
highlight some words, and so on. Most files can also be printed without reformatting, but the
raw printout may not look quite as nice.

Shivali Kumari 2237750 Page 78


Department of Information Technology

Many versions of UNIX include two powerful text formatters, nroff and troff. (There are
also versions called gnroff and groff.) They are much too complex to describe here. Before
we cover printing itself, let’s look at a simple formatting program called pr.

Option Description pr
-k Produces k columns of output. The
-d Double-spaces the output (not on all pr versions). pr
-h "header" Takes the next item as a report header.
-t Eliminates printing of header and top/bottom
margins.
command does minor formatting of files on the terminal screen or for a printer.
For example, if you have a long list of names in a file, you can format it onscreen
into two or more columns.

The syntax is:

pr option(s) filename(s)

pr changes the format of the file only on the screen or on the printed copy; it
doesn’t modify the original file. Table 4.2 lists some pr options.

Table 4-2. Some pr Options


Other options allow you to specify the width of the columns, set the page length,
and so on.

Before using pr, here are the contents of a sample file named food:

Shivali Kumari 2237750 Page 79


Department of Information Technology

% cat food

Sweet Tooth

Bangkok Wok

Mandalay

Afghani Cuisine

Isle of Java

Big Apple Deli

Sushi and Sashimi

Tio Pepe's Peppers

Let’s use pr options to make a two-column report with the header “Restaurants.”

Shivali Kumari 2237750 Page 80


Department of Information Technology

% pr -2 -h "Restaurants" food

Nov 7 9:58 1997 Restaurants Page 1

Sweet Tooth Isle of Java

Bangkok Wok Big Apple Deli

Mandalay Sushi and Sashimi Afghani

Cuisine Tio Pepe's Peppers

The text is output in two-column pages. The top of each page has the date and
time, header (or name of the file, if header is not supplied), and page number. To
send this output to the printer instead of the terminal screen, you create a pipe to
the printer program—usually lp or lpr. The following section describes lp and
lpr; Chapter 5 covers pipes.

lp and lpr
If you have a long file, it may be best to print it so you can see it all on paper.
The command lp or lpr prints a file (onto paper as opposed to the screen
display). Your system will probably have one or the other—but not both.

The syntax is:

lp

Shivali Kumari 2237750 Page 81


Department of Information Technology

option(s) filename(s) lpr


option(s) filename(s)

Printers on UNIX systems are usually shared by a group of users. After you enter
the command to print a file, the shell prompt returns to the screen and you can
enter another command. However, seeing the prompt doesn’t mean that your file
has been printed. Your file has been added to the printer queue to be printed in
turn.

Your system administrator has probably set up a default printer at your site.
To print a file named bills on the default printer, use the lp or lpr command,
as in this example:
lp bills (1 file)

request id is laserp-525

Task No.- 6

Shivali Kumari 2237750 Page 82


Department of Information Technology

Aim:- Implementation of Banker’s algorithm for the purpose of


deadlock avoidance.
Theory: Banker's Algorithm is used majorly in the banking system to avoid deadlock.
It helps you to identify whether a loan will be given or not. This algorithm is used to test for
safely simulating the allocation for determining the maximum amount available for all
resources.

Algorithm:
Safety Algorithm
The algorithm for finding out whether or not a system is in a safe state can be described as
follows:

1. Let Work and Finish be vectors of length ‘m’ and ‘n’ respectively.
Initialize: Work= Available
Finish [i]=false; for i=1,2,……,n
2. Find an i such that both
a) Finish [i]=false
b) Need_i<=work if no such i exists goto step (4)
3. Work=Work + Allocation_i
Finish[i]= true goto
step(2)
4. If Finish[i]=true for all i, then the system is in safe state.

Resource-Request Algorithm

Let Requesti be the request array for process Pi. Requesti [j] = k means process Pi wants k
instances of resource type Rj. When a request for resources is made by process Pi, the
following actions are taken:
1) If Requesti <= Needi
Goto step (2) ; otherwise, raise an error condition, since the process has exceeded its
maximum claim.

2) If Requesti <= Available


Goto step (3); otherwise, Pi must wait, since the resources are not available.

Shivali Kumari 2237750 Page 83


Department of Information Technology

3) Have the system pretend to have allocated the requested resources to process Pi by
modifying the state as follows:
Available = Available – Requesti
Allocationi = Allocationi + Requesti
Needi = Needi– Requesti

CODE:
#include <iostream>
using namespace std;
int main ()
{
int n, m, i, j, k;
int n = 5;
int m = 3;
int alloc[5][3] = { {0, 1, 0},
{2, 0, 0},
{3, 0, 2},
{2, 1, 1},
{0, 0, 2}};
int max[5][3] = { {7, 5, 3},
{3, 2, 2},
{9, 0, 2},
{2, 2, 2},
{4, 3, 3}};
int avail[3] = { 3, 3, 2 };
int f[n], ans[n], ind = 0;

for (k = 0; k < n; k++)


{
f[k] = 0;
}
int need[n][m];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
need[i][j] = max[i][j] - alloc[i][j];
}
int y = 0;
for (k = 0; k < 5; k++)
{
for (i = 0; i < n; i++)
{
if (f[i] == 0)
{
int flag = 0;
for (j = 0; j < m; j++)

Shivali Kumari 2237750 Page 84


Department of Information Technology

{
if (need[i][j] > avail[j])
{
flag = 1; break;
}
}
if (flag == 0)
{
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
int flag = 1;
for (int i = 0; i <n; i++)
{
if (f[i] == 0)
{
flag = 0;
cout << "The given sequence is not safe";
break;
}
}
if (flag == 1)
{
cout << "Following is the SAFE Sequence" << endl;
for (i = 0; i < n - 1; i++)
cout << " P" << ans[i] << " ->";
cout << " P" << ans[n - 1] << endl;
}
return 0;
}

OUTPUT:

Shivali Kumari 2237750 Page 85

You might also like