You are on page 1of 24

Operating System

Concepts
CS204 Operating Systems

By:
Dilum Bandara

Outline
p

OS concepts
n
n
n
n
n
n
n

Processes
Deadlocks
Memory management
Input/Output
Files
Security
Shell

Kernel
p User & kernel mode
p System calls
p

CSE-DB

Process
Process is a program in execution
p Includes:
p

n
n
n
n

executable program
program data
stack
various register status

CSE-DB

Process cont
p

In multitasking each process is


temporarily suspended from time to time
n

All information about the process should be


saved somewhere while suspending

Saved in the process table

When resuming process information is read


back from the process table

A process can create an another process


n

Forms a parent child relationship


CSE-DB

A process tree

n
n

A created 2 child processes, B & C


B created 3 child processes, D, E & F
CSE-DB

Deadlock

CSE-DB

Deadlocks in OSs
p

Occur due to resource sharing among


processes

If one process holds a resource & request


for another resource deadlock could occur

Example:
Process
Holds
Request
A
CD-ROM Tape drive
B
Tape drive CD-ROM

CSE-DB

Memory management
p

We need to run:
n
n

multiple programs at the same time


much larger programs

Protection becomes an issue while running


multiple programs
p Large program need large memory address
space
p

n
n
n

However main memory is limited


Need a virtual address space
More capacity is gained from hard disk
p Make use of swapping
CSE-DB

Input/Output
Many I/O devices used in modern
computers
p OS should manage them
p

Managed by the I/O subsystem

I/O software
n
n

Device dependent device drivers


Device independent

CSE-DB

Files
p

Data is stored in units called files on disks


& other media

Directories are used to organise/group


files

File system deals with files & directories

Files are located using the path name

In certain OSs I/O devices are also treated


as files
n

lp in Unix - /dev/lp
CSE-DB

10

Hierarchy of files

CSE-DB

11

Mounting file systems

Before mounting,
n

files on floppy are inaccessible

After mounting floppy on b,


n

files on floppy are part of file hierarchy


CSE-DB

12

Security
p

In multi-user systems privacy is important


n

Example:
n

Only authorised users should access files


-rwxrw-r-- firstyear user Jul 1 05:55 junk

OS should withstand other attacks


n
n
n

from unwanted intruders


from viruses
due to bugs in kernel & utilities

CSE-DB

13

The shell
Its another program that executes on top
of the OS
p Act as a command line interpreter
p It reads a command from standard input
& execute
p Commands can be classified as:
p

n
n

Internal commands cd, pwd


External commands ls, cp, sort

Examples
n

Bourne, Bash, C, ksh, Command prompt in DOS


CSE-DB

14

External commands
Commands which are implement as
individual programs
p Example:
n $ date
p

The shell creates a child process & run the


date program
n
n

While the child is running shell waits


When its finishes shell displays the prompt ($)
again & waits for the next command

External commands may run in foreground


or background
CSE-DB

15

Internal commands
p

Commands which are implemented within


the shell

Commands which need to keep track of


current state(s) are implemented within
the shell
n

cd change the current working directory

pwd reads the current working directory

Relative path names depend on current


working directory

CSE-DB

16

More on shell
p

Login shell
n

The shell that automatically executes when


you login

Changing the shell


n

Changing to a new default shell


p Need

to re-login

Creating additional shell sessions running on


top of, or concurrently with, the default shell

CSE-DB

17

Kernel
p

Kernel is the core of an OS


n

The real operating system

It is the program which:


n
n

provides services to applications


control resources
Log in Compilers Editors File

CSE-DB

U
t
i
l
i
t
i
e
s

Operating System
Machine language

Physical
devices

m
a
n
a
g
e
m
e
n
t

18

Web browser Banking Systems

User & Kernel mode


p

OS is the portion of software that runs in


the kernel mode
n

Also called the supervisor mode

Its protected from user tampering

Programs that runs on top of the OS run


in the user mode

Programs running in the user mode make


use of the services offered by the kernel

CSE-DB

19

System calls
p

The interface between OS & user programs


is defined by set of system calls

These system calls exposes the services


offered by the OS to user programs

These are set of functions/methods


n
n
n

Varies form one OS to another


Mostly written in assembly language & machine
dependent
Libraries are provided to make them accessible
from languages like C/C++
CSE-DB

20

Use of System calls


p

Opening a file
n n = read(fd, buffer, nbytes)
n
n
n
n

n number of bytes read into buffer


fd file descriptor
buffer pointer to buffer
nbytes buffer size

CSE-DB

21

Use of System calls cont


Library procedure
Return to caller
User
Space

Trap to Kernel
Put the code to read in register
User program
.
number=read(fd,buffer,nbytes);
.

Kernel
Space

System call handler


CSE-DB

22

Implementations of system calls


p

POSIX
n
n

Used in UNIX & Linux


About 100 system calls

Win32 API
n
n
n
n
n
n

Windows Application Program Interface


Supported since Windows 95
More than 1000 system calls
With each OS release new system calls are
introduced
Most of these calls are carried out in user mode
Much more complex compared to POSIX
CSE-DB

23

POSIX & Win32 API


POSIX

Win32 API

Description

fork

CreateProcess

Create a new process

execve

Replace the image of a


process

open

CreateFile

Create or open an existing


file

read

ReadFile

Read data from file

write

WriteFile

Write data to file

mkdir

CreateDirectory

Create a new directory

rmdir

RemoveDirectory

Remove an empty directory

time

GetLocalTime

Get the current time


CSE-DB

24

You might also like