0% found this document useful (0 votes)
81 views

OS CSL404 Lab Manual

The document is a lab manual for an Operating Systems course. It outlines 10 experiments related to exploring Linux commands like ls, cp, rm, exploring the file system, writing shell scripts, and implementing CPU scheduling algorithms like FCFS and Round Robin. The first experiment focuses on commands to list, copy, delete, rename files and change directories.

Uploaded by

WIZZIO
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

OS CSL404 Lab Manual

The document is a lab manual for an Operating Systems course. It outlines 10 experiments related to exploring Linux commands like ls, cp, rm, exploring the file system, writing shell scripts, and implementing CPU scheduling algorithms like FCFS and Round Robin. The first experiment focuses on commands to list, copy, delete, rename files and change directories.

Uploaded by

WIZZIO
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

Lab Manual

Programme (UG/PG): Computer Engineeering


Semester: IV
Course Code: CSL404
Course Title: Operating System
Prepared By: Mrs Kanchan Umavane
Approved By:
List of Experiments

Sr. Mapped
Name of Experiment
No CO
To explore the internal commands of linux like ls, cp, rm, mv, chdir, mkdir, cat, more, CSL404.1
1
date, cal, chmod, etc CSL404.2
To explore the internal commands of linux like head, tail, touch, pwd, wc, who, tty, ps, CSL404.1
2
kill, echo, etc CSL404.2
3 To write shell scripts to display current logged in user and log name CSL404.3
To write shell scripts to Display current shell, home directory, operating system type,
4 CSL404.3
current path setting, current directory
5 To illustrate the use of sort, grep, awk, etc
CSL404.1
CSL404.3
Write a program to for System calls of Linux operating system for creating parent & CSL404.2
6
child process using fork, getpid, exit, etc CSL404.6
7 Write a program to implement CPU scheduling algorithms for FCFS CSL404.4
8 Write a program to implement CPU scheduling algorithm for Round Robin CSL404.4
9 Write a program to implement dynamic partitioning placement algorithms for First-fit CSL404.5
10 Write a program to implement dynamic partitioning placement algorithms for Best Fit CSL404.5
Operating System

Experiment No.: 1

To explore the internal commands of


linux like ls, cp, rm, mv, chdir, mkdir, cat,
more, date, cal, chmod, etc
Experiment No. 1
1. Aim:To explore the internal commands of linux like ls, cp, rm, mv, chdir, mkdir, cat,
more, date, cal, chmod, etc
2. Objectives: To understand internal commands of Linux
3. Outcomes: Student will learn to use the internal commands of Linux
4. Hardware / Software Required:Computer System with Ubuntu
5. Theory:
Commands used:ls,cp,rm,mv,chdir,mkdir,cat,more,date,cal,chmod,etc.
Description with Examples:
1) ls: the ‘ls’ command simply displays the contents of directory
2) cp: the ‘cp’ commands stands for ‘copy’ & it simply copy/paste the file where you
want to
3) rm: the ‘rm’ command renames or delete any file or directories
4) mv: the ‘mv’ command stands for ‘move’ & it simply moves a file from a directory to
another directory
5) chdir: the ‘chdir’ command stands for ‘change directory’ and it changes current
directory to the New directory
6) mkdir: this command stands for ‘make directory’ and it creates a new directory.
7) cat: this command has further commands such as-
a) cat filename: displays the content of the file
b) cat>>filename: append the content to the file
c) cat file1>file2>file3: concatenate contents of more than one file into a new file
8) more: the ‘more’ command is used for paging through text one screen at a time.
9) date: the ‘date’ command is used to print out, or change the value of, the system's time
and date information
10) cal/ncal: ‘cal’ and ‘ncal’ display the current month in your terminal, with the current
day highlighted 11) chmod: ‘chmod’ is used to change the permissions of files or
directories.
11) pwd: ‘pwd’ command is used to print the name of working directory
6. Procedure/Program/Output:
student@project-OptiPlex-360:~/dir_1$pwd
/home/student/dir_1
student@project-OptiPlex-360:~/dir_1$ cat file cat: file: No such file or directory
student@project-OptiPlex-360:~/dir_1$ cat file_1 first directory
first file
A bright new start
student@project-OptiPlex-360:~/dir_1$df -m
Filesystem 1M-blocks Used Available Use% Mounted on
udev 965 0 965 0% /dev tmpfs 198 7 192 4% /run
/dev/sda1 65580 6578 55649 11% / tmpfs 988 38 951 4%
/dev/shmtmpfs 5 1 5 1% /run/lock tmpfs 988 0 988
0% /sys/fs/cgroup /dev/sda5 84355 170 79877 1% /boot /dev/sda6 74967
2368 68768 4% /home tmpfs 198 1 198 1% /run/user/1001
student@project-OptiPlex-360:~/dir_1$ du
8 ./dir_1_1/dir_1_2 16 ./dir_1_1
28 .
student@project-OptiPlex-360:~/dir_1$ cat >> file_1
4
5
6
7
8
9
10
11
12
^Z
[1]+
Stopped cat >> file_1
student@project-OptiPlex-360:~/dir_1$ cat file_1
first directory
first file A bright new start
4
5
6
7
8
9
10
11
12
student@project-OptiPlex-360:~/dir_1$ head file_1
first directory
first file A bright new start
4
5
6
7
8
9
10
student@project-OptiPlex-360:~/dir_1$ tail file_1
A bright new start
4
5
6
7
8
9
10
11
12
student@project-OptiPlex-360:~/dir_1$ tail -n3 file_1
10
11
12
student@project-OptiPlex-360:~/dir_1$ cat file_1
first directory
first file A bright new start
4
5
6
7
8
9
10
11
12
student@project-OptiPlex-360:~/dir_1$ cut -b 1,2,3 file_1.txt cut: file_1.txt: No such
file or directory
student@project-OptiPlex-360:~/dir_1$ cut -b 1,2,3 file_1 fir fir
Ab
4
5
6
7
8
9
10
11
12
student@project-OptiPlex-360:~/dir_1$ cat file_2
first directory first file
A bright new start
student@project-OptiPlex-360:~/dir_1$ cat>file_2 abcdeefghijklmnopqrs
^Z
[2]+ Stopped cat> file_2
student@project-OptiPlex-360:~/dir_1$ cut -b 1,2,3,4
^Z
[3]+ Stopped cut -b 1,2,3,4
student@project-OptiPlex-360:~/dir_1$ cat file_2 abcdeefghijklmnopqrs
student@project-OptiPlex-360:~/dir_1$ cut -b 1,2 file_2 ab efjk op
student@project-OptiPlex-360:~/dir_1$ cut -b 1,3 file_2 ac
eg
jl
oq
student@project-OptiPlex-360:~/dir_1$ cat file_1 first directory first file A bright new
start
4
5
6
7
8
9
10
11
12
student@project-OptiPlex-360:~/dir_1$ cat>file_1
red blue green pink grey white black yellow
^Z
[4]+Stopped cat> file_1
student@project-OptiPlex-360:~/dir_1$ sort file_1 black blue green grey pink red
white yellow
student@project-OptiPlex-360:~/dir_1$ sort -r file_1 yellow white red pink grey green
blue black
student@project-OptiPlex-360:~/dir_1$ncal
January 2018
Su 7 14 21 28
Mo 1 8 15 22 29
Tu 2 9 16 23 30
We 3 10 17 24 31
Th 4 11 18 25
Fr 5 12 19 26
Sa 6 13 20 27
student@project-OptiPlex-360:~/dir_1$cal
January 2018
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

student@project-OptiPlex-360:~/dir_1$ncal
January 2018
Su 7 14 21 28
Mo 1 8 15 22 29
Tu 2 9 16 23 30
We 3 10 17 24 31
Th 4 11 18 25
Fr 5 12 19 26
Sa 6 13 20 27
student@project-OptiPlex-360:~/dir_1$ncal -mfebruary
February 2018
Su 4 11 18 25
Mo 5 12 19 26
Tu 6 13 20 27
We 7 14 21 28
Th 1 8 15 22
Fr 2 9 16 23
Sa 3 10 17 24
student@project-OptiPlex-360:~/dir_1$ncal -y2020 ncal: invalid option -- '2'
Usage: cal [general options] [-hjy] [[month] year] cal [general options] [-hj] [-m
month] [year] ncal [general options] [-bhJjpwySM] [-s country_code] [[month] year]
ncal [general options] [-bhJeoSM] [year]
General options: [-NC31] [-A months] [-B months] For debug the highlighting: [-H yyyy-
mm-dd] [-d yyyy-mm]
student@project-OptiPlex-360:~/dir_1$ncal -y 2019
2019
January February March April
Su 6 13 20 27 3 10 17 24 3 10 17 24 31 7 14 21 28
Mo 7 14 21 28 4 11 18 25 4 11 18 25 1 8 15 22 29 Tu 1 8 15 22 29
5 12 19 26 5 12 19 26 2 9 16 23 30 We 2 9 16 23 30 6 13 20 27 6 13
20 27 3 10 17 24
Th 3 10 17 24 31 7 14 21 28 7 14 21 28 4 11 18 25
Fr 4 11 18 25 1 8 15 22 1 8 15 22 29 5 12 19 26
Sa 5 12 19 26 2 9 16 23 2 9 16 23 30 6 13 20 27

May June July August


Su 5 12 19 26 2 9 16 23 30 7 14 21 28 4 11 18 25
Mo 6 13 20 27 3 10 17 24 1 8 15 22 29 5 12 19 26
Tu 7 14 21 28 4 11 18 25 2 9 16 23 30 6 13 20 27
We 1 8 15 22 29 5 12 19 26 3 10 17 24 31 7 14 21 28
Th 2 9 16 23 30 6 13 20 27 4 11 18 25 1 8 15 22 29
Fr 3 10 17 24 31 7 14 21 28 5 12 19 26 2 9 16 23 30
Sa 4 11 18 25 1 8 15 22 29 6 13 20 27 3 10 17 24 31

September October November December


Su 1 8 15 22 29 6 13 20 27 3 10 17 24 1 8 15 22 29
Mo 2 9 16 23 30 7 14 21 28 4 11 18 25 2 9 16 23 30
Tu 3 10 17 24 1 8 15 22 29 5 12 19 26 3 10 17 24 31
We 4 11 18 25 2 9 16 23 30 6 13 20 27 4 11 18 25
Th 5 12 19 26 3 10 17 24 31 7 14 21 28 5 12 19 26
Fr 6 13 20 27 4 11 18 25 1 8 15 22 29 6 13 20 27
Sa 7 14 21 28 5 12 19 26 2 9 16 23 30 7 14 21 28
student@project-OptiPlex-360:~/dir_1$ncal -p
AL Albania 1912-11-30 IT Italy 1582-10-04
AT Austria 1583-10-05 JP Japan 1918-12-18
AU Australia 1752-09-02 LI Lithuania 1918-02-01
BE Belgium 1582-12-14 LN Latin 9999-05-31
BG Bulgaria 1916-03-18 LU Luxembourg 1582-12-14 CA Canada 1752-
09-02 LV Latvia 1918-02-01
CH Switzerland 1655-02-28 NL Netherlands 1582-12-14
CN China 1911-12-18 NO Norway 1700-02-18
CZ Czech Republic 1584-01-06 PL Poland 1582-10-04
DE Germany 1700-02-18 PT Portugal 1582-10-04
DK Denmark 1700-02-18 RO Romania 1919-03-31
ES Spain 1582-10-04 RU Russia 1918-01-31
FI Finland 1753-02-17 SI Slovenia 1919-03-04
FR France 1582-12-09 SW Sweden 1753-02-17
GB United Kingdom 1752-09-02 TR Turkey 1926-12-18
GR Greece 1924-03-09 *US United States 1752-09-02
HU Hungary 1587-10-21 YU Yugoslavia 1919-03-04
IS Iceland 1700-11-16
student@project-OptiPlex-360:~/dir_1$ncal -M
January 2018
Mo 1 8 15 22 29
Tu 2 9 16 23 30
We 3 10 17 24 31
Th 4 11 18 25
Fr 5 12 19 26
Sa 6 13 20 27
Su 7 14 21 28
student@project-OptiPlex-360:~/dir_1$ touch -a file_2
student@project-OptiPlex-360:~/dir_1$ ls dir_1_1 file_1 file_2
student@project-OptiPlex-360:~/dir_1$ ls -l
total 12
drwxrwxr-x 3 student student 4096 Jan 11 10:30 dir_1_1 -rwxr--r-- 1 student student 44
Jan 18 09:45 file_1 -rw-rw-r-- 1 student student 24 Jan 18 09:40 file_2
student@project-OptiPlex-360:~/dir_1$ date Thu Jan 18 10:09:31 IST 2018
student@project-OptiPlex-360:~/dir_1$ date -u Thu Jan 18 04:39:48 UTC 2018
student@project-OptiPlex-360:~/dir_1$ date --date=" 18th January " date: invalid date
‘ 18th January ’
student@project-OptiPlex-360:~/dir_1$ date --date="1/18/2018" Thu Jan 18 00:00:00
IST 2018
student@project-OptiPlex-360:~/dir_1$ date --date"3 year ago"
date: unrecognized option '--date3 year ago' Try 'date --help' for more information.
student@project-OptiPlex-360:~/dir_1$ date --date="3 year ago" Sun Jan 18 10:14:11
IST 2015
student@project-OptiPlex-360:~/dir_1$ date --date="8 sec ago" Thu Jan 18 10:14:27
IST 2018
student@project-OptiPlex-360:~/dir_1$ date --date="yesterday" Wed Jan 17 10:15:11
IST 2018

7. Conclusion :understood how the Linux system call and commands are run
Operating System

Experiment No.: 2

To explore the internal commands of


linux like head, tail, touch, pwd, wc, who,
tty, ps, kill, echo, etc
Experiment No. 2
1. Aim: To explore the internal commands of linux like head, tail, touch, pwd, wc, who,
tty, ps, kill, echo, etc.

2. Objectives: To understand more internal commands of Linux

3. Outcomes: Student will learn how to use internal commands of Linux

4. Hardware / Software Required: Any computer system with Ubuntu

5. Theory:

Commands used: head, tail, touch, pwd, wc, who, tty, ps, kill, echo, man etc
Description with examples:
1) head: ‘head’ by default, prints the first 10 lines of each FILE to standard output.
With more than one FILE, it precedes each set of output with a header identifying
the file name. If no FILE is specified, or when FILE is specified as a dash ("-"), head
reads from standard input
2) tail: ‘tail’ prints the last 10 lines of each file to standard output. If you specify
more than one file, each set of output is prefixed with a header showing the file name
3) touch: ‘touch’ command is used to create a file(not directory)
4) pwd: ‘pwd’ command is used to print working directory, it displays the directory
in which we are currently working.
5) wc: ‘wc’ stands for word count. It is used to find out Number of limes, word
count, byte & character count in the files specified in the file arguments
6) who: the ‘who’ command displays all the users who have logged into system
currently 7)tty: the ‘tty’ command is used to print the filename of the terminal
connected to standard input
8) ps: this command is used for viewing the process running on the system. It
provides snapshot of the current processes along with detailed information like
userid, cpu usage, memory usage, command name,etc
9) kill: this command is used to terminate process without having to logout or reboot
10) echo: ‘echo’ is a built in command for bash that is typically used in
scripting language & batch files to display a line of text/string on standard output

6. Procedure/Program/Output:
student@project-OptiPlex-360:~/dir_1$ cat file_3
this is the third file
demonstratingwc command
student@project-OptiPlex-360:~/dir_1$ wc file_3
2 8 48 file_3
student@project-OptiPlex-360:~/dir_1$ who student tty7 2016-02-11 21:59 (:0)
student@project-OptiPlex-360:~/dir_1$ who -l LOGIN tty1 2016-02-11 21:58 1348
id=tty1
student@project-OptiPlex-360:~/dir_1$ who -r run-level 5 2016-02-11 21:58
student@project-OptiPlex-360:~/dir_1$ w
23:36:24 up 1:38, 1 user, load average: 0.77, 0.59, 0.42
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
student tty7 :0 21:59 731days 1:36 0.19s /sbin/upstart -
student@project-OptiPlex-360:~/dir_1$ tty
/dev/pts/0
student@project-OptiPlex-360:~/dir_1$ ps
PID TTY TIME CMD
9849 pts/0 00:00:00 bash
11194 pts/0 00:00:00 cat
11221 pts/0 00:00:00 cat
11234 pts/0 00:00:00 cat
11247 pts/0 00:00:00 cat
11248 pts/0 00:00:00 cat
11332 pts/0 00:00:00 cat
11480 pts/0 00:00:00 cat 11585 pts/0 00:00:00 ps
student@project-OptiPlex-360:~/dir_1$ echo hello hi everyone hello hi everyone
student@project-OptiPlex-360:~/dir_1$ echo –e
student@project-OptiPlex-360:~/dir_1$ echo have a nice day have a nice day
student@project-OptiPlex-360:~/dir_1$ echo have \na \nnice \nday have nannicenday
student@project-OptiPlex-360:~/dir_1$ echo -e have \na \nnice \nday have
nannicenday
student@project-OptiPlex-360:~/dir_1$ kill -l

7. Conclusion: understood how the Linux system call and commands are run

Operating System
Experiment No.: 3

To write shell scripts to display current


logged in user and log name
Experiment No. 3
1. Aim: To write shell scripts to display current logged in user and log name
2. Objectives:To introduce basic concepts and functions of operating systems
3. Outcomes: Student will learn to write shell script to display current logged in user and
log name
4. Hardware / Software Required: Computer with Ubuntu
5. Theory:
‘echo’ is a fundamental command found in most operating systems. It is frequently used
in scripts, batch files, and as part of individual commands; anywhere you may need to
output text.
Most command shells, including bash, ksh and csh implement echo as a builtin
command. The behavior of builtin echo commands is similar, but the options may be
different; those commands are not documented here.
Syntax:
echo [SHORT-OPTION] [STRING] echo –help echo –version Short Options:
-n Do not output a trailing newline
-e Enable interpretation of backslash escape sequences
-E Disable interpretation of backslash escape sequences

6. Procedure/ Program:
#!/bin/sh
echo "Logged User : $(echo $USER)"
echo "Current date and time : $(date)"

7. Results:
Logged User : student
Current date and time : Mon Mar 5 12:24:10 IST 2018
8. Conclusion : understood how to write and execute the shell scripts run

Operating System
Experiment No.: 4

To write shell scripts to Display current


shell, home directory, operating system
type, current path setting, current
directory

Experiment No. 4
1. Aim: To write shell scripts to Display current shell, home directory, operating system
type, current path setting, current directory
2. Objectives : To introduce basic concepts and functions of operating systems, and how to
write scripts and shell commands using kernel APIs
3. Outcomes: Student will learn to write shell script to Display current shell, home
directory, operating system type, current path setting, current directory
4. Hardware / Software Required: Computer with Ubuntu
5. Theory:
A shell is special user program which provide an interface to user to use operating system
services. Shell accept human readable commands from user and convert them into
something which kernel can understand. It is a command language interpreter that
execute commands read from input devices such as keyboards or from files. The shell
gets started when the user logs in or start the terminal. Shell is broadly classified into two
categories –
 Command Line Shell
 Graphical shell
Shell can be accessed by user using a command line interface. A special program called
Terminal in linux/macOS or Command Prompt in Windows OS is provided to type in the
human readable commands such as “cat”, “ls” etc. and then it is being execute. The result
is then displayed on the terminal to the user.

6. Procedure/ Program:
#!/bin/sh
_mydir="`pwd`"
echo "dir: $_mydir"
echo "MY shell: $SHELL"
cat /etc/os-release
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
echo $SCRIPTPATH
7. Results:
dir: /home/student MY shell: /bin/bash
NAME="Ubuntu"
VERSION="16.04.2 LTS (XenialXerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.2 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
/home/student
8. Conclusion :Understood how access system variables using the shell scripts

Operating System
Experiment No.: 5

To illustrate the use of sort, grep, awk, etc

Experiment No. 5
1. Aim: To illustrate the use of sort, grep, awk, etc
2. Objectives: To introduce basic concepts and functions of operating systems, and how to
write scripts and shell commands using kernel APIs
3. Outcomes: Student will learn the use of sort, grep, awk, etc
4. Hardware / Software Required: Computer with Ubuntu
5. Theory:
1) Sort:
Name:
sort - sort lines of text files
Synopsis:
sort [OPTION]... [FILE]...
sort [OPTION]... --files0-from=F
Description:
Write sorted concatenation of all FILE(s) to standard output.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too. Ordering
options: -b, --ignore-leading-blanks ignore leading blanks -d, --dictionary-order
consider only blanks and alphanumeric characters
-f, --ignore-case
fold lower case to upper case characters
-g, --general-numeric-sort
compare according to general numerical value
-i, --ignore-nonprinting consider only printable characters -M, --month-sort
compare (unknown) < 'JAN' < ... < 'DEC'
-h, --human-numeric-sort
compare human readable numbers (e.g., 2K 1G)
-n, --numeric-sort
compare according to string numerical value
-R, --random-sort
shuffle, but group identical keys. See shuf(1)

2) GREP
Name:
grep, egrep, fgrep, rgrep - print lines matching a pattern
Synopsis:
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN]... [-f FILE]... [FILE...]

Description:
grep searches the named input FILEs for lines containing a match to the given.
By default, grep prints the matching lines.
In addition, the variant programs egrep, fgrep and rgrep are the same as grep - E, grep -F,
and grep -r, respectively.
These variants are deprecated, but are provided for backward compatibility.
Options:
Generic Program Information
--help Output a usage message and exit.
-V, --version
Output the version number of grep and exit.
Matcher Selection
-E, --extended-regexp

3) AWK
Name: gawk - pattern scanning and processing language
Synopsis:
gawk [ POSIX or GNU style options ] -f program-file [ -- ] file ...
gawk [ POSIX or GNU style options ] [ -- ] program-text file ...
Description:
Gawk is the GNU Project's implementation of the AWK programming
language. It conforms to the definition of the language
in the POSIX 1003.1 Standard. This version in turn is based on the description in The
AWK Programming Language, by Aho,
Kernighan, and Weinberger. Gawk provides the additional features found in the current
version of Brian Kernighan's awk and a number of GNU-specific extensions.
The command line consists of options to gawk itself, the AWK program text (if not
supplied via the -f or --file options), and values to be made available in the ARGC and
ARGV pre-defined AWK variables.
When gawk is invoked with the --profile option, it starts gathering profiling statistics
from the execution of the program. Gawk runs more slowly in this mode, and
automatically produces an execution profile in the file awkprof.out when done.

6. Procedure/ Program/Output:
student@project-OptiPlex-360:~/Desktop$ cat list1
2233|a.k.shukla |g.m |sales |12/12/52
2365|barun sengupta |director|production|11/05/47
9876|keval mhatre |chairman|admin |12/03/56 8752|varun gupta |d.g.m |personnel |
19/04/43
student@project-OptiPlex-360:~/Desktop$ sort -t"|" -k 1 list1
2233|a.k.shukla |g.m |sales |12/12/52
2365|barun sengupta |director|production|11/05/47
8752|varun gupta |d.g.m |personnel |19/04/43 9876|keval mhatre |chairman|admin |
12/03/56
student@project-OptiPlex-360:~/Desktop$ sort -t"|" -k 2 list1
2233|a.k.shukla |g.m |sales |12/12/52
2365|barun sengupta |director|production|11/05/47
9876|keval mhatre |chairman|admin |12/03/56 8752|varun gupta |d.g.m |personnel |
19/04/43
student@project-OptiPlex-360:~/Desktop$ sort -t"|" -k 3 list1
9876|keval mhatre |chairman|admin |12/03/56
8752|varun gupta |d.g.m |personnel |19/04/43
2365|barun sengupta |director|production|11/05/47
2233|a.k.shukla |g.m |sales |12/12/52
student@project-OptiPlex-360:~/Desktop$ sort -t"|" -k 4 list1
9876|keval mhatre |chairman|admin |12/03/56
8752|varun gupta |d.g.m |personnel |19/04/43
2365|barun sengupta |director|production|11/05/47
2233|a.k.shukla |g.m |sales |12/12/52
\
student@project-OptiPlex-360:~/Desktop$ sort -t"|" -k 5 list1
2365|barun sengupta |director|production|11/05/47
9876|keval mhatre |chairman|admin |12/03/56
2233|a.k.shukla |g.m |sales |12/12/52
8752|varun gupta |d.g.m |personnel |19/04/43

student@project-OptiPlex-360:~/Desktop$ cat fruits


mango apple banana grape guava Apple banana
student@project-OptiPlex-360:~$ cd Desktop
student@project-OptiPlex-360:~/Desktop$ grep -i "apple" fruits apple Apple
student@project-OptiPlex-360:~/Desktop$ grep -v "apple" fruits mango banana grape
guava Apple banana
student@project-OptiPlex-360:~/Desktop$ grep -n "apple" fruits
2:apple
student@project-OptiPlex-360:~/Desktop$ grep -c "apple" fruits
1
student@project-OptiPlex-360:~/Desktop$ grep -i -c "apple" fruits
2
student@project-OptiPlex-360:~/Desktop$awk '{print}' fruits mango apple banana
grape guava Apple
banana

7. Conclusion :Understood the working of Linux command for searching in file


Operating System

Experiment No.: 6

Write a program to for System calls of


Linux operating system for creating
parent & child process using fork, getpid,
exit, etc
Experiment No. 6
1. Aim: Write a program to for System calls of Linux operating system for creating parent
& child process using fork, getpid, exit, etc
2. Objectives: how toSystem calls of Linux operating system for process management
3. Outcomes: Student will learn to write a program to for System calls of Linux operating
system for creating parent & child process using fork, getpid, exit, etc
4. Hardware / Software Required: Computer with Ubuntu
5. Theory:
1) fork:
Name:
fork - create a child process
Synopsis:
#include <unistd.h>
pid_tfork(void);
Description:
fork() creates a new process by duplicating the calling process. The new process is
referred to as the child process. The calling process is referred to as the parent process.
The child process and the parent process run in separate memory spaces. At the time of
fork() both memory spaces have the same content. Memory writes, file mappings
(mmap(2)), and unmappings (munmap(2)) performed by one of the processes do not
affect the other.

2) getpid:
Name:
getpid, getppid - get process identification
Synopsis:
#include <sys/types.h> #include <unistd.h>pid_tgetpid(void); pid_tgetppid(void);
Description:
getpid() returns the process ID of the calling process. (This is often used by routines that
generate unique temporary filenames.) getppid() returns the process ID of the parent of
the calling process.

3) exit:
Name:
exit - cause normal process termination
Synopsis:
#include <stdlib.h>
void exit(int status);
Description:
The exit() function causes normal process termination and the value of status & 0377 is
returned to the parent (see wait(2)).
All functions registered with atexit(3) and on_exit(3) are called, in the reverse order of
their registration. (It is possible for one of these functions to use atexit(3) or on_exit(3) to
register an addi- tional function to be executed during exit processing; the new regis-
tration is added to the front of the list of functions that remain to be called.) If one of
these functions does not return (e.g., it calls _exit(2), or kills itself with a signal), then
none of the remaining functions is called, and further exit processing (in particular, flush-
ing of stdio(3) streams) is abandoned. If a function has been regis- tered multiple times
using atexit(3) or on_exit(3), then it is called as many times as it was registered.

6. Procedure/ Program:
#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>
int main(void)
{
pid_tpid;
printf("Before fork\n");
pid=fork();
if(pid>0)
{
sleep(1);
printf("PARENT--PID:%d PPID: %d,CHILD PID: %d\n",getpid(),getppid(),pid);
}
else if(pid==0)
printf("CHILD -- PID :%d\n",getpid(),getppid());
else
{
printf("Fork error\n");
exit(1);
}
printf("Both processes continue from here\n");
exit(0);
}

7. Results:
Before fork
CHILD -- PID :2818
Both processes continue from here
PARENT--PID:2817 PPID: 2772,CHILD PID: 2818
Both processes continue from here
8. Conclusion :Understood how to use theprocess management commands

Operating Systems
Experiment No.: 7

Write a program to implement CPU


scheduling algorithms for FCFS

Experiment No. 7
Implement and analyze different process
1. Aim: Write a program to implement CPU scheduling algorithms for FCFS
2. Objectives: Implement and analyze different process scheduling algorithms
3. Outcomes: Student will learn to write a program to implement CPU scheduling
algorithms for FCFS
4. Hardware / Software Required: Computer with Ubuntu
5. Theory:
First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm. FIFO (First
In First Out) strategy assigns priority to process in the order in which they request the
processor. The process that requests the CPU first is allocated the CPU first. This is
easily implemented with a FIFO queue for managing the tasks. As the process come in,
they are put at the end of the queue. As the CPU finishes each task, it removes it from the
start of the queue and heads on to the next task.
FCFS provides an efficient, simple and error-free process scheduling algorithm that saves
valuable CPU resources. It uses non-preemptive scheduling in which a process is
automatically queued and processing occurs according to an incoming request or process
order. FCFS derives its concept from real-life customer service.
For e.g.:
Suppose there are three processes in a queue: P1, P2 and P3. P1 is placed in the
processing register with a waiting time of zero seconds and 10 seconds for complete
processing. The next process, P2, must wait 10 seconds and is placed in the processing
cycle until P1 is processed. Assuming that P2 will take 15 seconds to complete, the final
process, P3, must wait 25 seconds to be processed. FCFS may not be the fastest process
scheduling algorithm, as it does not check for priorities associated with processes. These
priorities may depend on the processes' individual execution times.

6. Procedure/ Program:
#include<stdio.h>
int main()
{
intn,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20):"); scanf("%d",&n);
printf("\nEnter Process Burst Time\n");
for(i=0;i<n;i++)
{
printf("P[%d]:",i+1);
scanf("%d",&bt[i]);
}
wt[0]=0; //waiting time for first process is 0 //calculating waiting time
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j>i; j++);
wt[i]+=b[j];
}
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");
//calculating turnaround time
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
}
avwt/=i;
avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);
return 0;
}
7. Results:
Enter Process Burst Time
P[1]:24
P[2]:3
P[3]:3
Process Burst Time Waiting Time Turnaround Time
P[1] 24 0 24
P[2] 3 24 27
P[3] 3 27 30
Average Waiting Time:17
Average Turnaround Time:27
8. Conclusion : Understood and implemented the CPU scheduling algorithms for FCFS

Operating System
Experiment No.: 8

Write a program to implement CPU


scheduling algorithm for Round Robin

Experiment No. 8
1. Aim: Write a program to implement CPU scheduling algorithm for Round Robin
2. Objectives: Implement and analyze different process scheduling algorithms
3. Outcomes: Student will learn to write a program to implement CPU scheduling
algorithm for Round Robin
4. Hardware / Software Required: Computer with Ubuntu
5. Theory:
Round Robin Scheduling Algorithm:
1. The queue structure in ready queue is of First In First Out (FIFO) type.
2. A fixed time is allotted to every process that arrives in the queue. This fixed time is
known as time slice or time quantum.
3. The first process that arrives is selected and sent to the processor for execution. If it is
not able to complete its execution within the time quantum provided, then an interrupt is
generated using an automated timer.
4. The process is then stopped and is sent back at the end of the queue. However, the state
is saved and context is thereby stored in memory. This helps the process to resume from
the point where it was interrupted.
5. The scheduler selects another process from the ready queue and dispatches it to the
processor for its execution. It is executed until the time Quantum does not exceed.
6. The same steps are repeated until all the process are finished.
The round robin algorithm is simple and the overhead in decision making is very low. It
is the best scheduling algorithm for achieving better and evenly distributed response time.

6. Procedure/ Program:
#include<stdio.h>
int main()
{
intcount,j,n,time,remain,flag=0,time_quantum;
intwait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum);
printf("\n\nProcess\t|TurnaroundTime|Waiting Time\n\n"); for(time=0,count=0;remain!
=0;)
{
if(rt[count]<=time_quantum&&rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1) count=0;
else if(at[count+1]<=time)
count++;
else count=0;
}
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
printf("Avg Turnaround Time = %f",turnaround_time*1.0/n);
return 0;
}

7. Results:
Enter Total Process: 4
Enter Arrival Time and Burst Time for Process Process Number 1 :0
9
Enter Arrival Time and Burst Time for Process Process Number 2 :1
5
Enter Arrival Time and Burst Time for Process Process Number 3 :2
3
Enter Arrival Time and Burst Time for Process Process Number 4 :3 4
Enter Time Quantum: 5
Process |Turnaround Time|Waiting Time
P[2] | 9 | 4
P[3] | 11 | 8
P[4] | 14 | 10
P[1] | 21 | 12
Average Waiting Time= 8.500000
Avg Turnaround Time = 13.750000
8. Conclusion : Understood and implemented the CPU scheduling algorithm for Round
Robin
Operating System

Experiment No.: 9
Write a program to implement dynamic
partitioning placement algorithms for
First-fit

Experiment No. 9
1. Aim: Write a program to implement dynamic partitioning placement algorithms for First-
fit
2. Objectives: Implement and analyze different memory management algorithms
3. Outcomes: Student will learn to write a program to implement dynamic partitioning
placement algorithms for First-Fit
4. Hardware / Software Required: Computer with Ubuntu
5. Theory:
In this scheme we check the blocks in a sequential manner which means we pick the first
process then compare it’s size with first block size if it is less than size of block it is
allocated otherwise we move to second block and so on.
When first process is allocated we move on to the next process until all processes are
allocated. In the first fit, partition is allocated which is first sufficient from the top of
Main Memory.

Example :
Input :
blockSize[] = {100, 500, 200, 300, 600}; processSize[] = {212, 417, 112, 426};
Output:
Process No. Process Size Block no.
1 212 2
2 417 5
3 112 2
4 426 Not Allocated
• Its advantage is that it is the fastest search as it searches only the first block i.e. enough
to assign a process.
• It may problems of not allowing processes to take space even if it was possible to
allocate. Consider the above example, process number 4 (of size 426) does not get
memory. However it was possible to allocate memory if we had allocated using best fit
allocation {block number 4 (of size 300) to process 1, block number 2 to process 2, block
number 3 to process 3 and block number 5 to process 4}.

6. Procedure/ Program:
#include<stdio.h>
void main()
{
intbsize[10], psize[10], bno, pno, flags[10], allocation[10], i,j;
for(i = 0; i< 10; i++)
{
flags[i] = 0;
allocation[i] = -1;
}
printf("Enter no. of blocks: ");
scanf("%d", &bno);
printf("\nEnter size of each block: ");
for(i = 0; i<bno; i++)
scanf("%d", &bsize[i]);
printf("\nEnter no. of processes: ");
scanf("%d", &pno);
printf("\nEntersizeof each process:”);
for(i = 0; i<pno; i++)
scanf("%d", &psize[i]);
for(i = 0; i<pno; i++) //allocation as per first fit
for(j = 0; j <bno; j++)
if(flags[j] == 0 &&bsize[j] >= psize[i])
{
allocation[j] = i;
flags[j] = 1;
break;
}
//display allocation details
printf("\nBlock no.\tsize\t\tprocess no.\t\tsize");
for(i = 0; i<bno; i++)
{
printf("\n%d\t\t%d\t\t", i+1, bsize[i]);
if(flags[i] == 1)
printf("%d\t\t\t%d",allocation[i]+1,psize[allocation[i]]);
else
printf("Not allocated");
}
}

7. Results:
Enter no. of blocks: 3
Enter size of each block: 12
7
4
Enter no. of processes: 3
Enter size of each process: 7
4
9
Block no. size process no. size
1 12 1 7
2 7 2 4
3 4 Not allocated
8. Conclusion :Understood and implemented dynamic partitioning placement algorithms
for First-fit

Operating System

Experiment No.: 10

Write a program to implement dynamic


partitioning placement algorithms for
Best Fit
Experiment No. 10
1. Aim: Write a program to implement dynamic partitioning placement algorithms for Best
Fit
2. Objectives: Implement and analyze different memory management algorithms
3. Outcomes: Student will learn to write a program to implement dynamic portioning
placement algorithms for Best Fit
4. Hardware / Software Required: Computer with Ubuntu
5. Theory:
Best fit uses the best memory block based on the Process memory request. In best fit
implementation the algorithm first selects the smallest block which can adequately fulfill
the memory request by the respective process.
Because of this memory is utilized optimally but as it compares the blocks with the
requested memory size it increases the time requirement and hence slower than other
methods. It suffers from Internal Fragmentation which simply means that the memory
block size is greater than the memory requested by the process, then the free space gets
wasted.
Once we encounter a process that requests a memory which is higher than block size we
stop the algorithm.

6. Procedure/ Program:
void main()
{
int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999;
staticintbarray[20],parray[20];
printf("\n\t\t\tMemory Management Scheme - Best Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of processes:");
scanf("%d",&np);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block no.%d:",i);
scanf("%d",&b[i]);
}
printf("\nEnter the size of the processes :-\n");
for(i=1;i<=np;i++)
{
printf("Process no.%d:",i);
scanf("%d",&p[i]);
}
for(i=1;i<=np;i++)
{
for(j=1;j<=nb;j++)
{
if(barray[j]!=1)
{
temp=b[j]-p[i];
if(temp>=0)
if(lowest>temp)
{
parray[i]=j;
lowest=temp;
}
}
}
fragment[i]=lowest;
barray[parray[i]]=1;
lowest=10000;
}
printf("\nProcess_no\tProcess_size\tBlock_no\tBlock_size\tFragment");
for(i=1;i<=np &&parray[i]!=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,p[i],parray[i],b[parray[i]],fragment[i]);
}

7. Results:
Enter the number of blocks:5
Enter the number of processes:4
Enter the size of the blocks:- Block no.1:10
Block no.2:15
Block no.3:5
Block no.4:9
Block no.5:3
Enter the size of the processes :-
Process no.1:1
Process no.2:4
Process no.3:7
Process no.4:12
Process_noProcess_sizeBlock_noBlock_size Fragment
1 1 5 3 2
2 4 3 5 1
3 7 4 9 2
4 12 2 15 3
8. Conclusion :understood and implemented dynamic partitioning placement algorithms for
Best Fit

You might also like