INDEX
S.NO. Name of Experiment Page No. Remarks
1 Introduction To OS 3-6
2 Basic Commands in Linux 7-12
3 Shell Scripting in Linux 13-16
4 Conditional Statements if-else 17-18
5 Grep Commands 19
6 Hello World C Program 20
7 First Come First Serve 21-24
8 Shortest Job First 25-28
Operating System
Introduction
A computer system can be divided into 4 components: -
Hardware (CPU, memory, input/output devices, etc.),
Operating system,
System programs (word processors, spread sheets, accounting software’s, compilers,)
Application programs
In 1960’s definition of an operating system is “software that controls the hardware”.
However, today, due to microcode we need a better definition. We see an operating system as
the programs that make the hardware useable. In brief, an operating system is the set of
programs that controls a computer.
An Operating system is software that creates a relation between the User, Software and
Hardware. It is an interface between the all. All the computers need basic software known as
an Operating System (OS) to function.
The OS acts as an interface between the User, Application Programs, Hardware and the
System Peripherals. The OS is the first software to be loaded when a computers starts up. The
entire application programs are loaded after the OS.
Types of Operating System (Based of No. of user):
Single User: If the single user Operating System is loaded in computer’s memory; the
computer would be able to handle one user at a time.
Ex: MS-Dos, MS-Win 95-98, Win-ME.
Multi user: If the multi-user Operating System is loaded in computer’s memory; the
computer would be able to handle more than one user at a time.
Ex: UNIX, Linux, XENIX
Network: If the network Operating System is loaded in computer’s memory; the computer
would be able to handle more than one computer at time.
Ex: Novel Netware, Win-NT, Win-2000-2003CS6413
Command Prompt Interface:
Operating System provides a text based interface called command prompt. From the
command prompt commands can be issued to perform file and disk management and to run
program. Results of these commands are presented to the user as text message. C:\>-
The command prompt can be an alphabet followed by one colon (:), one back slash (\), one
greater than sign (>) and one blinking element called cursor (_).
Where C: represents the Drive letter (Current Drive)
\ represents the current folder / Directory
> represents the end of the Prompt and
_ blinking element (represents the Cursor)
Operating Systems Types
Single- And Multi-Tasking Operating Systems
A single-tasking system can only run one program at a time, while a multi-tasking operating
system allows more than one program to be running in concurrency. This is achieved by
time-sharing, dividing the available processor time between multiple processes that are each
interrupted repeatedly in time slices by a task-scheduling subsystem of the operating system.
Multi-tasking may be characterized in preemptive and co-operative types. In preemptive
multitasking, the operating system slices the CPU time and dedicates a slot to each of the
programs. Unix-like operating systems, e.g., Solaris, Linux, as well as AmigaOS support
preemptive multitasking.
Single- And Multi-User Operating Systems
Single-user operating systems have no facilities to distinguish users, but may allow multiple
programs to run in tandem. A multi-user operating system extends the basic concept of multi-
tasking with facilities that identify processes and resources, such as disk space, belonging to
multiple users, and the system permits multiple users to interact with the system at the same
time. Time-sharing operating systems schedule tasks for efficient use of the system and may
also include accounting software for cost allocation of processor time, mass storage, printing,
and other resources to multiple users.
Distributed Operating Systems
A distributed operating system manages a group of distinct computers and makes them
appear to be a single computer. The development of networked computers that could be
linked and communicate with each other gave rise to distributed computing. Distributed
computations are carried out on more than one machine. When computers in a group work in
cooperation, they form a distributed system.
Embedded Operating Systems
Embedded operating systems are designed to be used in embedded computer systems. They
are designed to operate on small machines like PDAs with less autonomy. They are able to
operate with a limited number of resources. They are very compact and extremely efficient
by design. Windows CE and “Minix 3”are some examples of embedded operating systems.
Real-Time Operating Systems
A real-time operating system is an operating system that guarantees to process events or data
by a specific moment in time. A real-time operating system may be single- or multi-tasking,
but when multitasking, it uses specialized scheduling algorithms so that a deterministic nature
of behavior is achieved. An event-driven system switches between tasks based on their
priorities or external events while time-sharing operating systems switch tasks based on clock
interrupts
Process Scheduling
Processes are the Small Programs those are executed by the user according to their Request.
CPU Executes all the Process according to Some Rules or Some Schedule. Scheduling ist hat
in which each process have Some Amount of Time of CPU. Scheduling Provides Time of
CPU to the Each Process.
Types of Process Scheduling
FCFS Scheduling Algorithm
The First Come First Served (FCFS) Scheduling Algorithm is the simplest one. In this
algorithm the set of ready processes is managed as FIFO (first-in-first-out) Queue. The
processes are serviced by the CPU until completion in order of their entering in the FIFO
queue.
A process once allocated the CPU keeps it until releasing the CPU either by terminating or
requesting I/O. For example, interrupted process is allowed to continujre running after
interrupt handling is done with.
SJF Scheduling Algorithm
The Shortest Job First Scheduling Algorithm chooses the process that has the smallest next
CPU burst.
SRTF: Shortest Remaining Time First
This is the preemptive version of SJF. The currently executing process will be preempted
from the CPU if a process with a shorter CPU burst time is arrived.
Round Robin Scheduling
This scheduling algorithm is designed especially for time sharing systems. It is similar to
FCFS scheduling, but preemption is added to switch between processes.
Basic Commands of Linux
To Create a New File
Syntax:- touch filename
To Create a New Directory
Syntax:- mkdir filename
To see Files and Directories
Syntax:- ls
To Create a Hidden Directory.
Syntax:- mkdir .filename
To Create a Hidden File
Syntax :- touch .filename
To See Hidden Files and Directories
Syntax:- ls –a
To See the authorised of long listing Files and Directories
Syntax: ls –l
To Enter Inside a Directory
Syntax :- cd directoryname
To Exit from all steps and returning to the parent
Syntax :- cd
To Enter into the last working Directory
Syntax :- cd –
To Exit form all previous steps
Syntax :- cd ..
To know the name of the Present Working Directory
Syntax :- pwd
To Locate binary, source and manual pages of commands in the Linux system.
Syntax :- whereis
To Open a file read-only mode.
Syntax :- cat filename
To open a file page-wise in read-only mode
Syntax :- less filename
**read_only mode
To Show date of the system
Syntax:- date
To Show the calender as per the system
Syntax:- cal
To Remove a File
Syntax:- rm filename
To Remove a Directory
sSyntax:- rmdir Directoryname
To Remove the Directory at root forcefully
Syntax:- rm –r directoryname
To Copy one File into another
Syntax:- cp filename1 filename2
To Copy a file into a Directory
Syntax:- cp filename directoryname
To Copy a Directory into another Directory
Syntax:- cp –a directory1 directory2
To move the contents of one file into another directory.
Syntax:- mv directoryname1 directoryname2
To Know the full description of Commands.
Syntax:- man commandname
To Clear the Screen
Syntax :- clear
To see long listing of hidden Files and Directories.
Syntax :- ls –a
To find in which Directory a specified file is locate
Syntax:- locate filename
To Show the Directory Space Usage
Syntax:- du
To Places the standard input into the file
Syntax:- cat >filename
Shell Scripting Programs in LInux
ADD Two Numbers
echo ”Enter first number”
read a
echo “Enter second number”
read b
c=’expr $a + $b’
echo “Sum: “$c
Subtract Two Numbers
echo ”Enter first number”
read a
echo “Enter second number”
read b
c=’expr $a - $b’
echo “Difference: “$c
Multiply Two Numbers
echo ”Enter first number”
read a
echo “Enter second number”
read b
c=’expr $a \* $b’
echo “Product: “$c
Divide Two Numbers
echo ”Enter first number”
read a
echo “Enter second number”
read b
c=’expr $a / $b’
d=’expr $a % $b’
echo “quotient: ”$c
echo “Remainder: “$d
Find Greatest Number Among Two Numbers
echo ”Enter first number”
read a
echo “Enter second number”
read b
if [$a –gt $b]
then
echo “a is greater”
else
echo”b is greater”
fi
Find Greatest Number Among Three Numbers
echo ”Enter first number”
read a
echo “Enter second number”
read b
echo ”Enter third number”
read c
if [$a –gt $b] && [$a –gt $c]
then
echo “a is greater”
elif [$b –gt $c] && [$b –gt $a]
echo ”b is greater”
else
echo ”c is greater”
fi
Find Whether The Number Is Even Or Odd
echo “Enter number”
read a
if [‘expr $a % 2 ‘ –eq 0 ]
then
echo “Number is even”
else
echo “Number is odd”
fi
To write a shell program to concatenate two strings
echo “enter the first string”
read str1
echo “enter the second string”
read str2
echo “the concatenated string is” $str1$str2
To write a shell program to compare the two strings.
echo “enter the first string”
read str1
echo “enter the second string”
read str2
if [ $str1 = $str2 ]
then
echo “strings are equal”
else
echo “strings are unequal”
fi
To write a shell program to generate fibonacci series.
echo enter the number
read n
a=-1
b=1
i=0
while [ $i –le $n ]
do
t=`expr $a + $b`
echo $t
a=$b
b=$t
i=`expr $i + 1
done
Conditional Statement ( if – else )
The if construct is followed by a command. If an expression is to be tested, it is enclosed in
square brackets. The then keyword is placed after the closing parenthesis. An if must end
with a fi.
Syntax :
1.if
This is used to check a condition and if it satisfies the condition if then does the next action ,
if not it goes to the else part.
2.if…else
Syntax :
If cp $ source $ target
Then
Echo File copied successfully
Else
Echo Failed to copy the file.
3.nested if
here sequence of condition are checked and the corresponding performed accordingly.
Syntax :
if condition
then
command
if condition
then
command
else
command
fi
fi
4.case ….. esac
This construct helps in execution of the shell script based on Choice.
GREP commands
Introduction:-
The grep filter searches a file for a particular pattern of characters, and displays all lines
that contain that pattern. The pattern that is searched in the file is referred to as the regular
expression (grep stands for globally search for regular expression and print out).
Syntax:
Hello WOrld !!
AIM:- To Write a C program to print Hello World.
Program:-
#include<stdio.h>
int main()
printf(“Hello World !!\n”);
}
/*helloworld.c*/
FIRST COME FIRST SERVE
AIM: To write a C program to implement the CPU scheduling algorithm for FIRST COME
FIRST SERVE.
PROBLEM DESCRIPTION: CPU Scheduler will decide which process should be
given the CPU for its execution.For this it use different algorithm to choose among the
process. one among that algorithm is FCFS algorithm.
In this algorithm the process which arrive first is given the CPU after finishing its request
only it will allow CPU to execute other process.
ALGORITHM:
Step1: Create the number of process.
Step2: Get the ID and Service time for each process.
Step3: Initially, Waiting time of first process is zero and Total time for the first process is the
starting time of that process.
Step4: Calculate the Total time and Processing time for the remaining processes.
Step5: Waiting time of one process is the Total time of the previous process.
Step6: Total time of process is calculated by adding Waiting time and Service time.
Step7: Total waiting time is calculated by adding the waiting time for lack process.
Step8: Total turn around time is calculated by adding all total time of each process.
Step9: Calculate Average waiting time by dividing the total waiting time by total number of
process.
Step10: Calculate Average turn around time by dividing the total time by the number of
process.
Step11: Display the result.
PROGRAM
#include<stdio.h>
struct process
int id,wait,ser,tottime;
}p[20];
main()
int i,n,j,totalwait=0,totalser=0,avturn,avwait;
printf("enter number of process");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("enter process_id");
scanf("%d",&p[i].id);
printf("enter process service time");
scanf("%d",&p[i].ser);
}
p[1].wait=0;
p[1].tottime=p[1].ser;
for(i=2;i<=n;i++)
for(j=1;j<=n;i++)
p[i].wait=p[i].wait+p[j].ser;
totalwait=totalwait+p[i].wait;
p[i].tottime=p[i].wait+p[i].ser;
totalser=totalser+p[i].tottime;
avturn=totalser/n;
avwait=totalwait/n;
printf("Id\tservice\twait\ttotal");
for(i=1;i<=n;i++)
printf("\n%d\t%d\t%d\t%d\n",p[i].id,p[i].ser,p[i].wait,p[i].tottime);
printf("average waiting time %d\n",avwait);
printf("average turnaround time %d\n",avturn);
OUTPUT
[admin@lab1cab5 admin]$ gcc fcfs.c
[admin@lab1cab5 admin]$ ./a.out
enter number of process4
enter process_id901
enter process service time4
enter process_id902
enter process service time3
enter process_id903
enter process service time5
enter process_id904
enter process service time2
average waiting time 5
average turnaround time 8
RESULT:
Thus the C program to implement CPU scheduling algorithm for first come first serve was
executed successfully
SHORTEST JOB FIRST
AIM: To write a C program to implement the CPU scheduling algorithm for Shortest job
first.
PROBLEM DESCRIPTION: CPU Scheduler will decide which process should be
given the CPU for its execution. For this it use different algorithm to choose among the
process. one among that algorithm is sjf algorithm.
In this algorithm the process which has less service time given the cpu after finishing its
request only it will allow cpu to execute next other process.
ALGORITHM:
Step1:Get the number of process.
Step2:Get the id and service time for each process.
Step3:Initially the waiting time of first short process as 0 and total time of first short is
process the service time of that process.
Step4:Calculate the total time and waiting time of remaining process.
Step5:Waiting time of one process is the total time of the previous process.
Step6:Total time of process is calculated by adding the waiting time and service time of each
process
Step7:Total waiting time calculated by adding the waiting time of each process.
Step8:Total turn around time calculated by adding all total time of each process.
Step9:calculate average waiting time by dividing the total waiting time by total number of
process.
Step10:Calculate average turn around time by dividing the total waiting time by total
number of process.
Step11:Display the result.
Program:-
#include<stdio.h>
struct ff
int pid,ser,wait;
}p[20];
struct ff tmp;
main()
int i,n,j,tot=0,avwait,totwait=0,tturn=0,aturn;
printf("enter the number of process");
scanf("%d",&n);
for(i=0;i<n;i++)
printf("enter process id");
scanf("%d",&p[i]);
printf("enter service time");
scanf("%d",&p[i].ser);
p[i].wait=0;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(p[i].ser>p[j].ser)
tmp=p[i];
p[i]=p[j];
p[j]=tmp;
printf("PID\tSER\tWAIT\tTOT\n");
for(i=0;i<n;i++)
tot=tot+p[i].ser;
tturn=tturn+tot; p[i+1].wait=tot;
totwait=totwait+p[i].wait;
printf("%d\t%d\t%d\t%d\n",p[i].pid,p[i].ser,p[i].wait,tot);
avwait=totwait/n;
aturn=tturn/n;
printf("TOTAL WAITING TIME :%d\n",totwait);
printf("AVERAGE WAITING TIME : %d\n",avwait);
printf("TOTAL TURNAROUND TIME :%d\n",tturn);
printf("AVERAGE TURNAROUND TIME:%d\n",aturn);
OUTPUT :
[root@lab1cab5 home]# ./a.out
enter the number of process4
enter process id701
enter service time6
enter process id702
enter service time4
enter process id703
enter service time8
enter process id704
enter service time1
TOTAL WAITING TIME :17
AVERAGE WAITING TIME : 4
TOTAL TURNAROUND TIME :36
AVERAGE TURNAROUND TIME:9
Result:
Thus the C program to implement the CPU scheduling algorithm for shortest job first was
executed successfully.