You are on page 1of 32

16CE068 CE221.

01 Operating Systems JAINIL PATEL

Sr.
No. Aim Of the Practical

1 Study Practical:
A. UNIX Architecture
B. Types of OS
C. Flavors of LINUX

1. Unix Architecture

Here is a basic block diagram of a Unix system −

 Kernel − The kernel is the heart of the operating system. It interacts with the
hardware and most of the tasks like memory management, task scheduling and file
management.

 Shell − The shell is the utility that processes your requests. When you type in a
command at your terminal, the shell interprets the command and calls the program
that you want. The shell uses standard syntax for all commands. C Shell, Bourne
Shell and Korn Shell are the most famous shells which are available with most of
the Unix variants.

 Commands and Utilities − There are various commands and utilities which you
can make use of in your day to day activities. cp, mv, catand grep, etc. are few
examples of commands and utilities. There are over 250 standard commands plus
numerous others provided through 3rd party software. All the commands come
along with various options.

 Files and Directories − All the data of Unix is organized into files. All files are then
organized into directories. These directories are further organized into a tree-like
structure called the filesystem.

16CE068 Page 1
16CE068 CE221.01 Operating Systems JAINIL PATEL

B. Types of OS

Single- and multi-tasking


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 AmigaOSsupport preemptive multitasking. Cooperative multitasking is achieved by relying on each
process to provide time to the other processes in a defined manner. 16-bit versions of Microsoft Windows
used cooperative multi-tasking. 32-bit versions of both Windows NT and Win9x, used preemptive multi-
tasking.

Single- and multi-user


Single-user operating systems have no facilities to distinguish users, but may allow multiple programs to
run in tandem.[6] 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
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.[7]

Templated
In an OS, distributed and cloud computing context, templating refers to creating a single virtual machine
image as a guest operating system, then saving it as a tool for multiple running virtual machines. The
technique is used both in virtualization and cloud computing management, and is common in large server
warehouses.[8]

Embedded
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
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

16CE068 Page 2
16CE068 CE221.01 Operating Systems JAINIL PATEL

C. Flavors of LINUX:

Widely used distributions

 Debian, a non-commercial distribution and one of the earliest, maintained by a volunteer developer
community with a strong commitment to free software principles and democratic project management
 Knoppix, the first Live CD distribution to run completely from removable media without installation
to a hard disk, derived from Debian
 Linux Mint Debian Edition (LMDE) uses Debian packages directly (rather than Ubuntu's)
 Ubuntu, a desktop and server distribution derived from Debian, maintained by British
company Canonical Ltd.
 Kubuntu, the KDE version of Ubuntu
 Linux Mint, a distribution based on and compatible with Ubuntu. Supports multiple desktop
environments, among others GNOME Shell forkCinnamon and GNOME 2 fork MATE.
 Trisquel, an Ubuntu-based distribution based on Linux-libre kernel composed entirely of free
software
 Elementary OS, an Ubuntu-based distribution with strong focus on the visual experience
without sacrificing performance.
 Fedora, a community distribution sponsored by American company Red Hat and the successor to the
company's previous offering, Red Hat Linux. It aims to be a technology testbed for Red Hat's
commercial Linux offering, where new open source software is prototyped, developed, and tested in
a communal setting before maturing into Red Hat Enterprise Linux.
 Red Hat Enterprise Linux (RHEL), a derivative of Fedora, maintained and commercially
supported by Red Hat. It seeks to provide tested, secure, and stable Linux server and
workstation support to businesses.
 CentOS, a distribution derived from the same sources used by Red Hat, maintained by a
dedicated volunteer community of developers with both 100% Red Hat-compatible versions
and an upgraded version that is not always 100% upstream compatible.
 Oracle Linux, which is a derivative of Red Hat Enterprise Linux, maintained and
commercially supported by Oracle
 Scientific Linux, a distribution derived from the same sources used by Red Hat, maintained
by Fermilab
 Mandriva Linux was a Red Hat derivative popular in several European countries and Brazil, backed
by the French company of the same name. After the company went bankrupt, it was superseded
by OpenMandriva Lx, although a number of derivatives now have a larger user base.
 Mageia, a community fork of Mandriva Linux created in 2010.
 PCLinuxOS, a derivative of Mandriva, which grew from a group of packages into a community-
spawned desktop distribution
 ROSA Linux, another former derivative of Mandriva, now developed independently
 openSUSE, a community distribution mainly sponsored by German company SUSE.
 SUSE Linux Enterprise, derived from openSUSE, maintained and commercially supported by
SUSE
 Arch Linux, a rolling release distribution targeted at experienced Linux users and maintained by a
volunteer community, offers official binary packages and a wide range of unofficial user-submitted
source packages. Packages are usually defined by a single PKGBUILD text file.
 Manjaro Linux, a derivative of Arch Linux that includes a graphical installer and other ease-of-use
features for less experienced Linux users. Rolling release packages from Arch repositories are

16CE068 Page 3
16CE068 CE221.01 Operating Systems JAINIL PATEL

held for further testing to achieve increased stability, and packages identified as addressing
security issues of critical or high severity are "fast-tracked" to the stable branch.
 Gentoo, a distribution targeted at power users, known for its FreeBSD Ports-like automated system
for compiling applications from source code
 Chrome OS, Google's commercial operating system (using Gentoo and its Portage) that primarily
runs web applications
 Chromium OS, the fully open-source version of Chrome OS
 Slackware, created in 1993, one of the first Linux distributions and among the earliest still
maintained, committed to remain highly Unix-like and easily modifiable by end users

Other distributions target specific niches, such as:

 Routers – for example, targeted by the tiny embedded router distribution OpenWrt
 Internet of things – for example, targeted by Ubuntu Core
 Home theater PCs – for example, targeted by KnoppMyth, Kodi (former XBMC) and Mythbuntu
 Specific platforms – for example, Raspbian targets the Raspberry Pi platform
 Education – examples are Edubuntu and Karoshi, server systems based on PCLinuxOS
 Scientific computer servers and workstations – for example, targeted by Scientific Linux
 Digital audio workstations for music production – for example, targeted by Ubuntu Studio
 Computer Security, digital forensics and penetration testing – examples are Kali Linux and Parrot
Security OS
 Privacy and anonymity – for example, targeted by Tails
 Offline use – for example, Endless OS

CONCLUSION:

Here we studied about the structure of linux and also some examples

16CE068 Page 4
16CE068 CE221.01 Operating Systems JAINIL PATEL

2 Study of Unix Architecture and the following Unix commands with option:
User Access: login, logout, passwd, exit

Help: man, help

Directory: mkdir, rmdir, cd, pwd, ls, mv

Editor: vi, gedit, ed, sed

File Handling / Text Processing: cp, mv, rm, sort, cat, pg, lp, pr, file, find, more, cmp,
diff, comm, head, tail, cut, grep, touch, tr, uniq

Security and Protection: chmod, chown, chgrp, newgrp

Information: learn, man, who, date, cal, tty, calendar, time, bc,
whoami, which, hostname, history, wc

System Administrator: su or root, date, fsck, init 2, wall, shut down, mkfs,
mount, unmount, dump, restor, tar, adduser, rmuser

Terminal: echo, printf, clear

Process: ps, kill, exec

I/O Redirection (<, >, >>), Pipe ( | ), *, gcc

1.
2. User Access
//Here Sudo is for superuser access
1)sudo login-----login to a different user in the terminal

16CE068 Page 5
16CE068 CE221.01 Operating Systems JAINIL PATEL

2) logout -----used to logout of user in terminal just like exit


gnome-session-quit -----logout the user

3) passwd-----used to change password of the user which is currently active

exit ------logout the user in the terminal which is logged in by login command same as logout

2.Help
man-----gives the manual page of command that is typed after it
Eg. man login

16CE068 Page 6
16CE068 CE221.01 Operating Systems JAINIL PATEL

help-----when written in the form help (command) it gives info about the specific command

Eg. help logout

3. Directory
mkdir-----used to create a folder
Eg. mkdir samplefolder

rmdir-----used to delete a folder


Eg. rmdir samplefolder

cd-----changes the present working directory

16CE068 Page 7
16CE068 CE221.01 Operating Systems JAINIL PATEL

pwd-----displays the present working directory

ls-----displays the list of files in current directory

mv ------ move (rename) files

4. Editor
vi----- a programmer’s text editor

16CE068 Page 8
16CE068 CE221.01 Operating Systems JAINIL PATEL

gedit------ opens a new gedit file(text file)

16CE068 Page 9
16CE068 CE221.01 Operating Systems JAINIL PATEL

ed----- open a line oriented text editor in terminal

sed-----stream editor for transforming text

16CE068 Page 10
16CE068 CE221.01 Operating Systems JAINIL PATEL

16CE068 Page 11
16CE068 CE221.01 Operating Systems JAINIL PATEL

5.
File Handling and Text Processing
cp-----it is used to copy a file or a folder

cp source_filename destination_directory

mv----- used to move a file or folder


mv source_filename destination_directory
eg. mv sample tutorial

16CE068 Page 12
16CE068 CE221.01 Operating Systems JAINIL PATEL

rm------used to delete a file


Eg. rm sample

Sort-----used to sort lines in a file

*original file

*sort sample

Cat------Used to concat data of multiple files


*sample file

*sample1 file

*cat sample sample1

16CE068 Page 13
16CE068 CE221.01 Operating Systems JAINIL PATEL

pg ----- browse pagewise through text files

lp-----used to print files

*lp sample

Didn’t printed as no printer available

Pr-----Convert text files for printing

*pr sample

File-----Determine file type

*file sample

Find-----Searches for file in the directory

*find sample

More----- file perusal filter for crt viewing

*more sample

cmp ----- compare two files byte by byte

16CE068 Page 14
16CE068 CE221.01 Operating Systems JAINIL PATEL

*cmp sample sample1

diff ------ compare files line by line

*diff sample sample1

comm ----- compare two sorted files line by line

head ----- output the first part of files

tail ----- output the last part of files

cut----- displays the bytes at specific positions from every line in a file

*cut -b 1 sample

the reason on this output is that h is first byte in first line , m is first byte in second line, I is first byte in third
line

Grep -----print lines that contains a specific pattern of text

16CE068 Page 15
16CE068 CE221.01 Operating Systems JAINIL PATEL

*grep is sample

touch ----- change file timestamps

tr ----- translate or delete characters or modify them

uniq ------ report or omit repeated lines

6.Security and Protection

Chmod-----used to change read and write permissions of a file

*chmod u=r sample


//this command makes the file only readable i.e user=read in command,,,,, group=g, others=o, w=write,
x=xecute

chmod u=r sample

16CE068 Page 16
16CE068 CE221.01 Operating Systems JAINIL PATEL

chown ----- change file owner

Eg. sudo chown root sample

Here root is name of user


Sample is name of file
Sudo is for superuser access

The file is now under root owner

Chgrp-----Used the changed the group of file

16CE068 Page 17
16CE068 CE221.01 Operating Systems JAINIL PATEL

Newgrp-----Used to login to a new group


8.Information
who ----- show who is logged on
*who

Date-----gives the current date and time

Cal-----gives the calendar

tty ----- print the file name of the terminal connected to standard input

Calendar ----- reminder service

16CE068 Page 18
16CE068 CE221.01 Operating Systems JAINIL PATEL

time ------ run programs and summarize system resource usage

bc ----- An arbitrary precision calculator language

Whoami-----gives the name of user which is logged in

Which-----locates the location of a command

Hostname-----shows the name of the host

16CE068 Page 19
16CE068 CE221.01 Operating Systems JAINIL PATEL

History-----gives the history of all commands you typed

16CE068 Page 20
16CE068 CE221.01 Operating Systems JAINIL PATEL

wc ----- print newline, word, and byte counts for each file
*wc sample

9.System Administrator (need to write sudo su before using all commands)

16CE068 Page 21
16CE068 CE221.01 Operating Systems JAINIL PATEL

Su or root----- gives you superuser or root rights for commands

fsck ----- check and repair a Linux filesystem

init-----init basically defines how the system has to boot up


how to write:- init 1 , init 2 ,init 3

Run Name Description


level

0 Halt Shuts down the system

1 Single-user mode Mode for administrative tasks.

2 Multi-User Mode Does not configure network interfaces and does not
export networks services

3 Multi-User Mode with Starts the system normally


Networking

4 Not used / user For special purposes


definable

5 Start the system Run level 3 + display manager


normally with GUI
display manager

6 Reboot Reboots the system

16CE068 Page 22
16CE068 CE221.01 Operating Systems JAINIL PATEL

s or S Single-user mode Not configure network interface or start daemon

wall ----- write a message to all users

shutdown ----- Halt, power-off or reboot the machine

mkfs ----- build a Linux filesystem

mount ----- mount a filesystem

16CE068 Page 23
16CE068 CE221.01 Operating Systems JAINIL PATEL

adduser-----used to add a new user or group to the os

userdel-----used to delete a user

10.Terminal
Echo-----used to print a message

16CE068 Page 24
16CE068 CE221.01 Operating Systems JAINIL PATEL

Printf----- format and print data (mostly used in scripting with variables)

Clear-----clear the terminal screen


After typing clear

11.I/O Redirection

16CE068 Page 25
16CE068 CE221.01 Operating Systems JAINIL PATEL

command > file Redirection of output


command >> file Appends output to specified file
command < file Redirection of input
command 2 > file Redirection of error messages (stdin, stdout and stderr are
associated with numerical values 0, 1 and 2 - called file descriptors)

Some Examples Using Redirection Commands

To send the output produced by the who command to the file called wholist:

Type: who > wholist

To create a file called demo :

Type: cat > demo

To run the program myprog taking input from the file called data and sending the output to the file
called results :

Type: myprog < data > results

CONCLUSION

Here We studied different commands in linux and executed them.

3 1. Write a shell script which calculates nth Fibonacci number where n will be provided as input when
prompted.
Solution:

16CE068 Page 26
16CE068 CE221.01 Operating Systems JAINIL PATEL

echo "Enter the number of terms you want "

read n

a=0

b=1

echo -n $a $b

for(( i=2;i<$n;i++ ))

do

c=$(( $a + $b ))

a=$b

b=$c

echo -n " " $c

done

echo " "


Output:

2. Write a shell script which takes one number from user and finds factorial of a given number.
Solution:
echo -n "enter number::"

16CE068 Page 27
16CE068 CE221.01 Operating Systems JAINIL PATEL

read no1
fact=1
for(( i=1;i<=$no1;i++ ))
do
fact=$(( $fact * $i ))
done
echo "Factorial is "$fact

Output:

3. Write a shell script to sort the number in ascending order. (Using array).

echo "enter the size of the array"


read n

echo "enter Numbers in array:"


for (( i = 0; i < $n; i++ ))
do
read nos[$i]
done

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


do
for (( j = 0; j < $i; j++ ))
do
if [ ${nos[$i]} -lt ${nos[$j]} ]; then
t=${nos[$i]}
nos[$i]=${nos[$j]}
nos[$j]=$t
fi
done
done

16CE068 Page 28
16CE068 CE221.01 Operating Systems JAINIL PATEL

echo -e "\nSorted Numbers "


for (( i=0; i < $n; i++ ))
do
echo -n ${nos[$i]}" "
done
echo ""

Output:

CONCLUSION

Here we implemented factorial , Fibonacci and Bubble sorting in shell scripting

4 1. Write a shell script which will take a file name from the user and finds that whether the file is there or not
in a current working directory and displays the appropriate message.
Solution:
echo -n "Enter file name "

16CE068 Page 29
16CE068 CE221.01 Operating Systems JAINIL PATEL

read filename

f=0

for i in $(ls)
do
if [ $i = $filename ]
then
f=1
break
fi
done

if [ $f -eq 1 ]
then echo "file found"
else echo "Not Found"
fi

Output:

2. Write a shell script which compares two files given by the user and if both files are same then
delete the second one, if not then merge the two files in a new file.
Solution:

16CE068 Page 30
16CE068 CE221.01 Operating Systems JAINIL PATEL

if [ $# -eq 2 ]

then

file1=$1

file2=$2

else

echo " Enter name of file one : "

read file1

echo " Enter name of file two : "

read file2

fi

f1=0

f2=0

for i in $(ls)

do

if [ $file1 = $i ]

then

f1=1

echo "file 1 found"

fi

if [ $file2 = $i ]

then

f2=1

16CE068 Page 31
16CE068 CE221.01 Operating Systems JAINIL PATEL

echo "file 2 found"

fi

done

f3=$(( $f1 + $f2 ));

if [ $f3 -eq 2 ]

then

cmp $file1 $file2

if [ $? -eq 0 ]

then

rm $file2

else

cat $file1 $file2 > file3.txt

fi

else

echo "File not found"

fi

Output:

Conclusion: we studied file handling in shell script.

16CE068 Page 32

You might also like