IT7411
IT7411
IT7411
ANNA UNIVERSITY
DEPARTMENT OF INFORMATION TECHNOLOGY
To educate students with conceptual knowledge and technical skills in the field of
Information Technology with moral and ethical values to achieve excellence in an academic,
industry and research centric environment.
1. To inculcate in students a firm foundation in theory and practice of IT skills coupled with
the thought process for disruptive innovation and research methodologies, to keep pace with
emerging technologies.
2. To provide a conducive environment for all academic, administrative, and interdisciplinary
research activities using state-of-the-art technologies.
3. To stimulate the growth of graduates and doctorates, who will enter the workforce
as productive IT engineers, researchers, and entrepreneurs with necessary soft skills, and
continue higher professional education with competence in the global market.
4. To enable seamless collaboration with the IT industry and Government for consultancy and
sponsored research.
5. To cater to cross-cultural, multinational, and demographic diversity of students.
6. To educate the students on the social, ethical, and moral values needed to make significant
contributions to society.
After completion of the B.Tech. (IT) course, students will be able to:
PSO1: To apply programming principles and practices for the design of software solutions in
an internet-enabled world of business and social activities.
PSO2: To identify the resources to build and manage the IT infrastructure using the current
technologies in order to solve real world problems with an understanding of the trade-offs
involved in the design choices.
PSO3: To plan, design and execute projects for the development of intelligent systems with a
focus on the future
Exercises
1. Basic unix commands such as ls, cd, mkdir, rmdir, cp, rm, mv, more, lpr, man, grep, sed,
etc.,
2. Shell script
3. Process control System calls - demonstration of fork, execute and wait
4. Thread management
5. Thread synchronization
6. Deadlock avoidance using semaphores
7. Interprocess communication using pipes
8. Interprocess communication using FIFOs
9. Interprocess communication using signals
10. Implementation of CPU scheduling policy in Linux
11. Implement a memory management policy in Linux
12. Implement a file system in Linux
13. Linux kernel configuration
TOTAL: 60 PERIODS
OUTCOMES:
On Completion of the course, the students should be able to:
Learn the concepts to identify, create and maintain the basic command in operating
systems
Express strengths and limitations of various managements schemes in operating
systems
Explain the core issues of operating systems
Implement algorithms of operating systems.
Program Outcomes(POs)
CO PSO1 PSO2 PSO3
1 2 3 4 5 6 7 8 9 10 11 12
Learn the 1 2 3 1 1 1 0 0 0 0 0 2 2 2 2
concepts to
identify, create
and use the
basic command
in operating
systems
Familiarize 1 2 3 2 1 0 0 0 0 0 0 1 2 2 2
strengths and
limitations of
various
managements
schemes in
operating
systems
Implement core 1 2 2 3 3 1 0 0 0 0 1 1 2 2 2
concepts/ issues
of operating
systems
Implement 1 2 2 3 3 2 2 0 0 0 1 1 2 2 2
algorithms of
operating
systems
Exploration of 1 2 2 3 3 2 2 0 0 0 1 1 2 2 2
memory
management
methodologies
Exploration of 1 2 3 3 3 3 3 1 0 0 1 1 2 2 2
interprocess
communication
strategies
5. SHELL ARRAYS
AIM
To the study the functions of an operating system.
1.1 OVERVIEW
An Operating System (OS)(as shown in Fig 1) is an interface between a
computer user and computer hardware. An operating system is a software
which performs all the basic tasks like file management, memory management,
process management, handling input and output, and controlling peripheral
devices such as disk drives and printers.
Some popular Operating Systems include Linux Operating System,
Windows Operating System, VMS, OS/400, AIX, z/OS, etc. Following are some
of important functions of an operating System:
Memory Management
Processor Management
Device Management
File Management
Security
Control over system performance
Job accounting
Error detecting aids
Coordination between other software and end users.
Linux provides a standard file structure in which system files/ user files
are arranged.
Security
RESULT
The architecture and features of an operating system has been studied
successfully.
1. cat
The cat command is used to create a file.
The cat command is used to display the contents of a file.
The cat command is also used merge multiple files into a single file
Syntax
$ cat > filename (Create a new file)
$ cat <filename> (Display the contents of file)
$ cat file1 file2 >file3 (merge the contents of file1, file2 into file 3)
1.1 File Creation & Display its Contents using cat command
2. ls command
Listing files and directories
The ls command is used to display the contents of a directory.
Syntax
$ ls View the contents of directory
Syntax
$ mkdir <dname>
2. rmdir
This command is used remove a directory from the disk
3. cd
This command is used to move from one directory to another directory.
Syntax
$ cd <dname>
3.1 Changing the Working Directory
3. tty command
The tty (teletype) command is used to print the current terminal name
$ tty
RESULT
Thus the linux commands have been studied and executed
successfully.
AIM
To execute the fundamentals of shell programming such as control flow
statements.
EXISTING PROBLEM
It is not possible to perform more than one task at a time using shell
command
SHELL SCRIPTS (MULTITASKING)
In order to solve the problems of shell command, the shell programming
is introduced here
Doing more than one job at a time (multitasking)
It is also called as shell programming
VARIABLES SECTION
Names given to the memory location
Shell program supports dynamic data typed system which means that
no need to use specific data type for variables declaration
Syntax
Variable-Name=Initial-Value
Example
2. OUTPUT
:’ Variable Declarations
a=20
k=25
‘
SELECTION STATEMENTS
1. Simple If statement
2. If else Statement
3. If else if Statement
4. Case Statement
if [ condition ]
then
true statement
fi
It is an important to note that, the space should be given before and after
the operator symbol [
You can use test keyword instead of the operator symbols [ ]
2. If else Statement
Syntax
if [ condition ]
then
true statement
else
false statement
fi
if [ condition ]
then
true statement
elif [ condition ]
then
true statement
else
false statement
fi
It is an important to note that, the simple if, if else and if-elif-else should
be closed by fi keyword.
4. Case Statement
It is equivalent to switch case statements in c language
It is used to execute several statements based on the value of expression
This is done by using the reserved word case
It is an alternative option for if..elif..else statements
Syntax
case <variable> in
Pattern 1)
Commands / statements
;;
Pattern 2)
Commands / statements
;;
…
easc
LOOPING STATEMENTS
1. While loop
Syntax
while [ condition ]
do
true statement
done
SOURCE CODE
while :
do
echo "Hello World"
done
(OR)
while true
do
echo "Hello World"
OUTPUT
Syntax
until [ condition ]
do
true statement
done
echo "---------------------------------------------"
echo "\t\tUntil Loop Example"
echo "---------------------------------------------"
i=1
until [ $i -gt 5 ] Here the looping statements are executed
do until the condition becomes fail like 1>5,
echo $i 2>5, 3>5, 4>5, 5>5
i=`expr $i + 1`
done
3. For loop
Syntax
for variable in w1 w2 … wn
do
true statement
done
Where,
Variable can be any user defined name
w1 w2 …wn list of the values separated by spaces
echo "-------------------------------------"
echo "\t For Loop Example"
echo "-------------------------------------"
for i in 12 14 15 17 18 21
do
echo $i
done
OUTPUT
echo "-----------------------------------------------------------"
echo "\t Char & String Retrieval using for loop"
echo "-----------------------------------------------------------"
for i in 'Sachin' 'B' "C" "D" ‘E’
do
echo $i
done
echo "---------------------------------------------------------------"
echo "\t Listing Files and Folder using for loop"
echo "---------------------------------------------------------------"
# get all the files and store them to variable
fset=`ls`
Store list of files to the variable fset using
k=1
ls command.
# loop the variable fset
for i in $fset
do
echo "$k. $i" k=k+1 or k++
k=`expr $k + 1`
done
Command Substitution:
Storing the output of command to a user defined variable.
This is done by using the operator `command` or $(command)
SOURCE CODE
echo "--------------------------------------------"
echo "\t\tFactorial Program"
echo "--------------------------------------------"
echo "Enter a number : "
read n
i=0
f=1
while [ $i -lt $n ]
OUTPUT
echo "------------------------------------------------"
echo "\t\tFactorial Program- C Style"
echo "------------------------------------------------"
echo "Enter a number : "
read n
i=1
f=1
# while loop
while [ $i -le $n ]
do
# expression 1 in c-style
f=$((f*i))
# expression 2 in c-style
i=$((i+1))
done
echo "Factorial of $n is $f"
OUTPUT
echo "--------------------------------------------"
echo "\t\tReverse of Number"
echo "--------------------------------------------"
echo "Enter a number : " Read a number
read n
duplicate=$n
while (n!=0)
res=0
while [ $n -ne 0 ]
do rem=n%10
# find the reminder
rem=`expr $n % 10`
res=res*10
# multiply reverse number with 10
res=`expr $res \* 10`
# add the resultant number with remainder number
res=`expr $res + $rem`
# divide n by 10
n=n/10
n=`expr $n / 10`
done
echo "The Reverse Number of $duplicate is $res"
X. ARMSTRONG NUMBER
SOURCE CODE
echo "--------------------------------------------"
echo "\t\tArmstrong Number"
echo "--------------------------------------------"
echo "enter a number"
read n
# variables declarations
dup=$n while (n!=0)
arm=0
# while loop
while test $n -ne 0
rem=n%10
do
# find remainder of a number
rem=`expr $n % 10`
# multiply rem with three times rem=(rem*rem*rem)
OUTPUT
while [ true ]
do
echo "-------------------------------------"
echo "\t\t Menu Program"
echo "-------------------------------------"
echo "1. View Files \t 2.Date"
echo "3. Users List \t4.Calendar"
echo "5. Exit"
NOTE
It is an important to note that, the single equal operator (=) is used for
string comparison and the symbol –eq or == is used for number
comparison in the shell program.
r=`expr $a + $b`
echo "Sum is: $r"
else
echo "No inputs are submitted...Please submit the CMD inputs..."
fi
OUTPUT
RESULT
Thus the basics of shell programming was executed successfully.
ARITHMETIC OPERATORS
S.N OPERATOR DESCRIPTION
1. + Addition
2. - Subtraction
3. * Multiplication
4. / Division
EXPRESSION IN SHELLS
Shell provides two options for performing expressions in shell scripts.
They are
NOTE
It is an important to note that, the operator * does not provide the
multiplication in shell expression using expr command. Because in shell,
the operator * means wild card characters.
read b
# performing arithmetic operations using expr command
r1=$((a+b))
r2=$((a-b))
r3=$((a*b))
r4=$((a/b))
# print the results
echo "Add: \t$r1"
echo "Sub: \t$r2"
echo "Mul: \t$r3"
echo "Div: \t$r4"
RELATIONAL OPERATORS
RELATIONAL OPERATORS FOR NUMBERS [ using $() ]
S.N OPERATOR DESCRIPTION
1. == Equal
2. != Not Equal
3. < Lesser than
4. <= Lesser than or Equal to
5. > Greater than
6. >= Greater than or Equal to
OUTPUT
done
OUTPUT
1. Content Permissions
CONTENT PERMISSION
In content permission, the column 1 indicates the file type. They are
function <name>
{
# user code
}
Example
function show
{
# user code
}
Syntax2
<function-name>()
{
# user code
}
Example
show()
{
# user code
}
CALLING FUNCTION
Shell function can be called using its name only.
The operation () should not be used while calling the function.
$ function-name
Example
$ show
OUTPUT
OUTPUT
COMMAND SUBSTITUTION
In shell, assigning the built-in command to a user defined variable is
called as command substitution
Syntax1
Variable-Name=`command-name`
Example
dirpath=”test”
files=`ls $dirpath ` # the contents of test directory are stored
to the variable called files
Syntax 2
Variable-Name=$(command-name)
Example
OUTPUT
# k=$(ls $path)
src=`ls $path` Path of Source Directory (d1). Parent
Path can be get using pwd command.
path of target directory
tar="/home/runner/OS-Lab/d5"
# for loop
for i in $src Path of Target Directory (d5).
do
cp $i $tar
echo "$i is successfully copied to $tar/$i"
done
echo "-----------------------------------------------------"
OUTPUT
RESULT
Thus the operators and shell functions of the shell programming have
been executed successfully.
Where,
Element 1, Element 2, …Element n can be Same Type or Different
Type.
Example
Length
Array length can be done by using the special symbol # followed by @
or * symbol along with array name
It is very important to note that, the curly braces operators {} are used
for accessing the array in shell
Syntax
{#<array-name>[@]}
(OR)
{#<array-name>[*]}
ls=(12 34 55 99)
len=${#ls[@]}
(OR)
len=${#ls[*]}
ls[0] 12
ls[1] 32
${arrayname[index-number]}
Example
OUTPUT
OUTPUT
OUTPUT
echo "-------------------------------------------------"
echo "Shell Array for Same Type of Elements"
echo "-------------------------------------------------"
# Array Creation
lb=()
# assigning linux commands to the each location of array
lb[0]=$(ls)
lb[1]=$(date)
lb[2]=`cal`
lb[3]=`cat /etc/shells`
# print the length of the array
echo "Length of the Array: ${#lb[@]}"
echo "Array Contents using for loop"
echo "-------------------------------------------------"
# print the contents of array
for i in ${lb[*]}
do
echo $i
done
RESULT
Thus the arrays using shell programming have been executed
successfully.
AIM
To practice the system calls such as fork, wait, exit using linux c
programming.
SYSTEM CALLS
It is an interface between process and kernel
1. Process Control
2. File Management
3. Device Management
4. Information Management
5. Communication
Functions
End and Abort
Load and Execute
Create Process and Terminate Process
Wait and Signed Event
Allocate and free memory
2. File Management
It handles file manipulation jobs like creating a file, reading, and writing,
etc.
Functions
Create a file
Delete file
Open and close file
Read, write, and reposition
Get and set file attributes
3. Device Management
It performs the job of device manipulation like reading from device
buffers, writing into device buffers, etc.
Functions
Request and release device
Logically attach/ detach devices
Get and Set device attributes
4. Information Management
It handles information and its transfer between the OS and the user
program.
Functions
Get or set time and date
Functions
Create, delete communications connections
Examples
S.N Linux Windows Description
1. fork() CreateProcess() Create a child process
2. exit() ExitProcess() Terminate the process
3. wait() WaitForSignalObject() Wait for the child process
termination
fork()
It is an important system calls which is used to create a new process in
the OS
The newly created process is called as child process and caller of the
child process is called as parent process
It is called once but returns twice (once in parent and once in the child)
The new process gets a copy of the current program, but new process id
(pid). The process id of the parent process (the process that called fork())
is registered as the new processes parent pid (ppid) to build a process
tree.
Child Process
The newly created process is called as child process
Parent Process
The caller of the newly created process is called as parent process
Formula
Total number of processes (T) : 2n
Total number of Child processes (C) : 2n-1
Total number of Child processes (P) : T-C
NOTE
After the fork(), both parent and child processes are running
simultaneously
Program statements before fork() is common for both child and parent
processes but after fork() call, the rest of the program instructions will be
allocated separately for child and parent process
Child and parent processes don’t share common address space. They
are having own memory address space. So if there are any changes in
child process won’t reflect the parent process. Similarly, if there are any
changes in parent processes won’t reflect the child process.
As soon as a process is ready for execution (i.e. the fork system call
returns), it may run according to the scheduling configuration (priority,
scheduler chosen, etc.).
2. #include<unistd.h>
This header file is used for fork(), getpid(), getppid(), etc, …
3. #include<sys/types.h>
This header file is used for pid_t, etc, …
4. #include<sys/wait.h>
This header file is used for wait(), etc, …
5. #include<stdlib.h>
This header file is used for exit(), etc, …
TOOLS SUPPORT
Compiler : gcc compiler (gcc <filename>.c)
Execution : ./a.out (assembly output)
OS : Linux OS platform
Terminal : Online linux terminal (www.replit.com)
OUTPUT
When the child process is created, both the parent process and the child
process will point to the next instruction (same Program Counter) after
the fork().
OUTPUT
OUTPUT
1. getpid()
2. getppid()
1. getpid()
It is a built-in function and available in #include<unistd.h> header file
2. getppid()
It is a built-in function and available in #include<unistd.h> header file
pid_t
It stands for process id type and built-in variable to store the process ids
of parent and child function
It is available in #include<sys/types.h>
Wait()
It is system call and available in #include<sys/wait.h> file
It blocks the current process (calling process), until one of its child
processes terminate or a signal is received
If more than one child processes are terminated, then it returns process
ID of any terminated arbitrary child process.
2. If there is no child process running when the call to wait() is made, then
this wait() has no effect at all. It returns -1 immediately.
If child finishes before parent reaches wait(NULL) then it will read the exit
status, release the process entry in the process table and continue
execution until it finishes as well.
Wait can be used to make the parent process wait for the child to
terminate (finish) but not the other way around
Once child process finishes, parent resumes and prints the rest of the
statements of parent process
exit()
It is system call and available in #include<stdlib> file
It is used to close all files, sockets, frees all memory and then terminates
the process.
RESULT
Thus the types of process system calls have been executed
successfully.
IPC
Shared Memory
Message Queues
Sockets
Signals
PIPES
Pipe provides the communication between processes on same computer
or different computer or across the network
pd[0] pd[0]
Process 1 (P1) Process 2
(P2)
pd[1] pd[1]
Example
Here, pipe system call accepts only one argument, which is an integer
array of two pipe descriptors.
pd[0] is used for reading data / message from the pipe and pd[1] is used
for writing data / message to the pipe.
Pipe (Unnamed Pipe or Anonymous Pipe)
In linux, if the pipe has no name then it is called as unnamed pipe or
anonymous pipe (gives communication between parent and child
processes)
It is a communication medium between two or more related or interrelated
processes
It is mainly used for interprocess communication. It has two ends. They
are:
1. First end is fd[0] which is used for reading mode
2. Second end is fd[1] which is used for writing mode
It is used for transferring data between two processes / commands /
programs
It acts like queue data structure. We can write 512 bytes at the same time
but we can read ONLY ONE BYTE at the same time.
It is an important to note that, pipe is an uni-directional (half duplex or
one-way communication) that is either from left to right or right to left
It is an important to note that, whatever is written on one end (Ex. write
end) might visible on other end (Ex. read end)
#include<unistd.h>
OPERATIONS OF PIPE
One Way Communication between processes
This method will return the number of bytes written on success case and
will return -1 if the case is failure.
This method will return the number of bytes read on success case and
will return -1 if the case is failure.
3. close(pipe-descriptor)
This method is used to close the pipe if pipe is already opened
It takes only one argument which is the integer value of pipe descriptor
OUTPUT
IF INPUT IS 18
IF INPUT IS 31
OUTPUT
RESULT
Thus the interprocess communication using pipe has been executed
successfully.
NOTE
Neither pipes nor FIFO allow file positioning. Both reading and writing
operations happen sequentially that is reading from the beginning of the
file and writing at the end of the file.
Required Header File
CAPACITY OF FIFO
It has multiple readers or multiple writers
Bytes from each writer are written automatically up to a maximum size of
PIPE_BUF (4KB on Linux OS)
SOURCE CODE
#include <stdio.h>
#include<sys/stat.h>
#include<string.h>
#include<fcntl.h>
#include <unistd.h>
// global variables
char m1[]="Hello World.";
char m2[]="Good Morning.";
char m3[]="Welcome to Chennai.\n";
void sendMessage()
{
int fd;
// create new file (FIFO) for create and write mode with necessary permission
fd=open("sms.txt",O_CREAT| O_WRONLY,0777);
// write the three messages to named pipe
write(fd,m1,strlen(m1));
int main()
{
printf("------------------------------------------------------\n");
printf("\t\tIPC using FIFO (Named Pipe)\n");
printf("------------------------------------------------------\n");
sendMessage();
RESULT
Thus the interprocess communication using named pipe has been
executed successfully.
AIM
To practice the multithreading programming using python language.
THREADING
Thread is a path of the execution within a process.
2. Multithreading
2. Runnable state
4. Blocked state
BUILT-IN METHODS
1. start()
This is runnable state (waiting for the execution)
This is method is used to start the thread
Thread(name=<user-defined-name, target=<function-name>, )
It is a built-in class which is used to create a new thread object
First argument is name of thread. It can be any name set by the user. It
is optional argument
Required Module
threading
SOURCE CODE
from threading import *
# user defined function
def welcome():
print("Hello World...")
print("------------------------------------------") Newborn state
print("\tSingle Thread")
print("------------------------------------------")
# creating object for single thread Runnable state
OUTPUT
Sub Thread
t1
MULTITHREADING
Process of executing more than one thread at the same time (Execution
of multiple threads simultaneously)
It is an important to note that, we can’t predict which thread will run first.
By all the threads will be running in parallel at the same time.
It is an important to note that, the main or current thread can randomly
start any thread from the list of threads.
SOURCE CODE
from threading import *
# user defined function 1
def m1():
for i in range(3):
print("Good Morning...")
# user defined function 2
def m2():
Pictorial Diagram
SOURCE CODE
from threading import *
# user defined function 1
def m1():
for i in range(3):
print("Good Morning...")
# user defined function 2
def m2():
for i in range(3):
print("Good Evening...")
SOURCE CODE
from threading import *
import threading
# user defined function 1
def m1():
tname=threading.currentThread().getName()
print("Current Thread\t: ",tname)
print("Good Morning...")
# user defined function 2
def m2():
tname=threading.currentThread().getName()
print("Current Thread\t: ",tname)
print("Good Evening...")
# user defined function 3
def m3():
tname=threading.currentThread().getName()
print("Current Thread\t: ",tname)
print("Good Night...")
# main thread
print("-----------------------------------------------------------")
print("\tFinding Current Thread - Multithreading")
print("-----------------------------------------------------------")
# creating objects for multiple threads
t1=Thread(target=m1,name="Morning")
t2=Thread(target=m2,name="Evening")
t3=Thread(target=m3,name="Night")
OUTPUT
1. Daemon thread
2. Non daemon thread (User Thread)
1. Daemon Thread
If a thread is running in background mode, then it is called as daemon
thread
It has low priority level than user thread
This is created by adding the boolean value to the daemon argument of
the Thread class.
SOURCE CODE
from threading import *
from time import sleep
# user defined function 1
def m1():
for i in range(3):
print("Good Morning...")
sleep(2)
# user defined function 2
def m2():
for i in range(3):
print("Good Evening...")
# user defined function 3 Convert user thread to non-
def m3(): daemon thread.
for i in range(3):
print("Good Night...")
print("------------------------------------------------")
print("\tDaemon Thread")
print("------------------------------------------------")
# creating objects for multiple threads
# convert thread t1 to daemon thread by setting the boolean true to the
daemon argument of thread class
t1=Thread(target=m1,name="Morning", daemon=True)
# non daemon threads
t2=Thread(target=m2,name="Evening")
t3=Thread(target=m3,name="Night")
OUTPUT
NOTE
In the above output screenshot, the daemon thread t1 Good Morning
is still running in the background mode.
Eventhough all threads (including main thread) are terminated, the
daemon thread is still aliving and running in the background.
SOURCE CODE
from threading import *
from time import sleep
# user defined function 1
def m1():
for i in range(3):
print("Good Morning...")
sleep(2)
# user defined function 2
def m2():
for i in range(3):
print("Good Evening...")
# user defined function 3
def m3():
for i in range(3):
print("Good Night...")
print("----------------------------------------------------------")
print("\tNon Daemon Thread(User Threads)")
print("----------------------------------------------------------")
# creating objects for multiple threads
# Non Daemon Threads
t1=Thread(target=m1,name="Morning")
t2=Thread(target=m2,name="Evening")
t3=Thread(target=m3,name="Night")
# start the threads by calling start method
t1.start()
OUTPUT
RESULT
Thus the multithreading programming using python has been executed
successfully.
AIM
To practice the file allocation strategy in linux programming.
FILE ALLOCATION METHODS
It defines, how the files are stored in the disk blocks.
BENEFITS
Efficient disk space utilization
Example 2
In the index block, the ith entry holds the disk address of the ith file
block.
It is an important to note that, indexed block does not hold the file data,
but it holds the pointers to all the disk blocks allotted to the particular file.
The directory entry contains the address of the index block as shown in
the below image:
PICTORIAL REPRESENTATION
Directory Entry
}
// if counter equals to exact length, then slot should be free
if(c==length)
{
// allocate file / block for the user request
for(int i=0;i<length;i++)
{
b[ib[i]]=1;
printf("Index block %d is allocated ...\n",ib[i]);
}
printf("File is allocated successfully for the block %d\n",number);
}
// if the submitted index block is greater than MAXIMUM give message
else
{
printf("File lengths are not free for the given block\n");
}
RESULT
Thus the file allocation strategies like sequential and indexed file
allocation methods have been executed successfully.