OS File Shivali 2237750
OS File Shivali 2237750
OS File Shivali 2237750
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.
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.
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.
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.
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.
Distributed systems use many processors located in different machines to provide very fast
computation to its users.
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:
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.
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.
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
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
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.
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.
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:
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.
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.
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
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
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
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
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
System requirement:
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.
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.
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.
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.
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.
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.
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.
You can also connect to a wireless network if Ubuntu recognizes your wireless adapter.
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.
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.
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
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.
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.
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.
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.
If you don’t have any other operating systems installed, Ubuntu will begin automatically
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).
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.
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
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.
Step 1.2: Uncheck “Create a shortcut in the Quick Launch Bar” and click “Next”
Step 1.6: After completion of Installation process, the Virtual Box Window gets opened
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.
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.
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.
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.
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.
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.
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.
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.
Step 12: Once you've selected it, click OK. Then double-click your virtual machine to start it
up.
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.
Step 15: Once it's started up, just follow the regular installation procedure as if you were
installing.
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.
Maximum throughput
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.
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.
It is the preemptive form of SJF. In this algorithm, the OS schedules the Job according to the
remaining time of the execution.
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.
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.
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.
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.
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:
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 :-
Implementation of FCFS :-
#include<iostream>
int main()
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
cin>>n;
for(i=0;i<n;i++)
cout<<"P["<<i+1<<"]:";
cin>>bt[i];
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
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;
return 0;
Output:-
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++)
{
Output:-
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>
void findWaitingTime (int processes[], int n, int bt[], int wt[], int quantum)
int rem_bt[n];
rem_bt[i] = bt[i];
int t = 0;
while (1)
if (rem_bt[i] > 0)
done = false;
t += quantum;
rem_bt[i] -= quantum;
else
t = t + rem_bt[i];
wt[i] = t - bt[i];
rem_bt[i] = 0;
void findTurnAroundTime (int processes[], int n, int bt[], int wt[], int tat[])
cout << "Processes " << " Burst time " <<" Waiting time " << " Turn around time\
n";
cout << " " << i +1 << "\t\t" << bt[i] << "\t " << wt[i] << "\t\t " << tat[i] << endl;
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 burst_time[] = { 7, 4, 3, 4 };
int quantum = 2;
return 0;
Output:-
Shivali Kumari 2237750 Page 45
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>
int main()
int n;
float avg1=0;
float avg2=0;
cin>>n;
int i;
int x,y,z;
{ x=i+1;
cin>>y;
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]; }
for(i=0;i<n;i++)
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;
return 0;
Output:-
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.
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.
cd [DIRNAME]
Cd home/user/Desktop
cd ~/Desktop
d.
cd ~username
cd /home/user/Desktop/files/
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 a b
Example:- cp a b
mkdir COMMAND :-
mkdir [DIRNAME]
mkdir 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.
mv [OLD] [NEW]
mv newDir ChangedDir
mv newDir ~/Documents/Dirs
This command will remove newDir from the current directory and move it to ~/Documents/Dirs.
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:
3. To exit the prompt and write the changes to the file, hold the Ctrl key and press d.
cat >test2.txt
5. Type:
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.
#1) cmp: This command is used to compare two files character by character.
• 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.
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.
• ‘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
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.
● 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.
Example : 1. Listing all files and directories and give it as input to more command.
$ ls -l | more
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.
Fg
You can use the command “fg” to continue a program which was stopped and bring it to the foreground.
Example:-
Priority
PR 20 20
Can be 20(highest) or -20(lowest)
NI The nice value of a task 0 0
Status S R
‘S’ = sleeping
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.
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
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.
To start a process with a niceness value other than the default value use the following syntax nice -n
If there is some process already running on the system, then you can ‘Renice’ its value using syntax.
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.
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.
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.
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.
BANNER Command :- Banner command in linux is used to print the ASCII character string in
large letter to standard output.
Syntax : banner text
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.
File1_name File2_name....n
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.
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'.
Here,
4 is number of lines.
16 is number of words.
80 is number of bytes.
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:
Shell Types:-
There are again various subcategories for Bourne Shell which are listed as follows:
A shell is a command-line interpreter and typical operations performed by shell scripts include file
manipulation, program execution, and printing text.
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
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.
Objective:
• To perform arithmetic operation using expr.
• To execute conditional statement
o if [condition] then
statement
fi
o if [condition] then
statement else
fi
Theory:
if [statement]
then statement
else
fi
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)
A variable is nothing more than a pointer to the actual data. The shell enables
you to create, assign, and delete variables.
Variable Names
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
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
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
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.
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.
fi else while do
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.
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.
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.
Before using pr, here are the contents of a sample file named food:
% cat food
Sweet Tooth
Bangkok Wok
Mandalay
Afghani Cuisine
Isle of Java
Let’s use pr options to make a two-column report with the header “Restaurants.”
% pr -2 -h "Restaurants" food
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.
lp
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
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.
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;
{
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: