02-OS Concepts View

Embed Size (px)

Citation preview

  • 8/20/2019 02-OS Concepts View

    1/24

    Operating SystemConcepts

    CS204 – Operating Systems

    By:

    Dilum Bandara

  • 8/20/2019 02-OS Concepts View

    2/24

    © CSE-DB 2

    Outlinep OS concepts

    n Processes

    n Deadlocks

    n Memory management

    n Input/Output

    n Files

    n Security

    n Shell

    p Kernelp User & kernel mode

    p System calls

  • 8/20/2019 02-OS Concepts View

    3/24

    © CSE-DB 3

    Processp Process is a program in execution

    p Includes:

    n executable program

    n program data

    n

    stackn various register status

  • 8/20/2019 02-OS Concepts View

    4/24

    © CSE-DB 4

    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

    n Saved in the process table

    n When resuming process information is readback from the process table

    p A process can create an another process

    n Forms a parent child relationship

  • 8/20/2019 02-OS Concepts View

    5/24

    © CSE-DB 5

     A process tree

    n A created 2 child processes, B & Cn B created 3 child processes, D, E & F

  • 8/20/2019 02-OS Concepts View

    6/24

    © CSE-DB 6

    Deadlock 

  • 8/20/2019 02-OS Concepts View

    7/24

    © CSE-DB 7

    Deadlocks in OSsp Occur due to resource sharing among

    processes

    p If one process holds a resource & requestfor another resource deadlock could occur

    p Example:

    CD-ROMTape driveB

    Tape driveCD-ROMA

    RequestHoldsProcess

  • 8/20/2019 02-OS Concepts View

    8/24

    © CSE-DB 8

    Memory managementp We need to run:

    n multiple programs at the same time

    n much larger programs

    p Protection becomes an issue while running

    multiple programsp Large program need large memory address

    space

    n However main memory is limited

    n Need a virtual address spacen More capacity is gained from hard disk

    pMake use of swapping

  • 8/20/2019 02-OS Concepts View

    9/24

    © CSE-DB 9

    Input/Outputp Many I/O devices used in modern

    computers

    p OS should manage them

    n Managed by the I/O subsystem

    p I/O softwaren Device dependent – device drivers

    n Device independent

  • 8/20/2019 02-OS Concepts View

    10/24

    © CSE-DB 10

    Files

    p Data is stored in units called files on disks& other media

    p Directories are used to organise/groupfiles

    p File system deals with files & directories

    p Files are located using the path name

    p In certain OSs I/O devices are also treated

    as files

    n   lp in Unix - /dev/lp

  • 8/20/2019 02-OS Concepts View

    11/24

    © CSE-DB 11

    Hierarchy of files

  • 8/20/2019 02-OS Concepts View

    12/24

    © CSE-DB 12

    Mounting file systems

    p Before mounting,n files on floppy are inaccessible

    p After mounting floppy on b,n files on floppy are part of file hierarchy

  • 8/20/2019 02-OS Concepts View

    13/24

    © CSE-DB 13

    Securityp In multi-user systems privacy is important

    n Only authorised users should access files

    p Example:n -rwxrw-r-- firstyear user Jul 1 05:55 junk

    p OS should withstand other attacksn from unwanted intruders

    n from viruses

    n due to bugs in kernel & utilities

  • 8/20/2019 02-OS Concepts View

    14/24

    © CSE-DB 14

    The shellp It’s another program that executes on top

    of the OS

    p Act as a command line interpreter

    p It reads a command from standard input

    & executep Commands can be classified as:

    n Internal commands – cd, pwd

    n External commands – ls, cp, sort

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

  • 8/20/2019 02-OS Concepts View

    15/24

    © CSE-DB 15

    External commandsp Commands which are implement as

    individual programs

    p Example:

    n $ date

    p The shell creates a child process & run thedate program

    n While the child is running shell waits

    n When it’s finishes shell displays the prompt ($)

    again & waits for the next commandp External commands may run in foreground

    or background

  • 8/20/2019 02-OS Concepts View

    16/24

    © CSE-DB 16

    Internal commandsp Commands which are implemented within

    the shell

    p Commands which need to keep track ofcurrent state(s) are implemented within

    the shelln cd change the current working directory

    n pwd reads the current working directory

    n Relative path names depend on current

    working directory

  • 8/20/2019 02-OS Concepts View

    17/24

    © CSE-DB 17

    More on shellp Login shell

    n The shell that automatically executes when

    you login

    p Changing the shell

    n Changing to a new default shell

    pNeed to re-login

    n Creating additional shell sessions running ontop of, or concurrently with, the default shell

  • 8/20/2019 02-OS Concepts View

    18/24

    © CSE-DB 18

    Kernelp Kernel is the core of an OS

    n The real operating system

    p It is the program which:

    n provides services to applications

    n control resources

    Physical

    devices

    Machine language

    Operating System

    Compilers Editors management

    File

    Util

    ities

    Web browser Banking Systems

    Log in

  • 8/20/2019 02-OS Concepts View

    19/24

    © CSE-DB 19

    User & Kernel modep OS is the portion of software that runs in

    the kernel mode

    n Also called the supervisor mode

    n It’s protected from user tampering

    p Programs that runs on top of the OS runin the user mode

    p Programs running in the user mode makeuse of the services offered by the kernel

  • 8/20/2019 02-OS Concepts View

    20/24

    © CSE-DB 20

    System callsp The interface between OS & user programs

    is defined by set of system calls

    p These system calls exposes the servicesoffered by the OS to user programs

    p These are set of functions/methodsn Varies form one OS to another

    n Mostly written in assembly language & machine

    dependent

    n Libraries are provided to make them accessiblefrom languages like C/C++

  • 8/20/2019 02-OS Concepts View

    21/24

    © CSE-DB 21

    Use of System callsp Opening a file

    n n = read(fd, buffer, nbytes)

    n n – number of bytes read into buffer

    n fd – file descriptor

    n buffer – pointer to buffer

    n nbytes – buffer size

  • 8/20/2019 02-OS Concepts View

    22/24

    © CSE-DB 22

    Use of System calls cont…

    ………….

    number=read(fd,buffer,nbytes);

    ………….

    System call handlerKernelSpace

    UserSpace

    User program

    Trap to Kernel

    Put the code to read in register

    Return to caller

    Library procedure

  • 8/20/2019 02-OS Concepts View

    23/24

    © CSE-DB 23

    Implementations of system callsp POSIX

    n Used in UNIX & Linux

    n About 100 system calls

    p Win32 API

    n Windows Application Program Interface

    n Supported since Windows 95

    n More than 1000 system calls

    n With each OS release new system calls areintroduced

    n Most of these calls are carried out in user mode

    n Much more complex compared to POSIX

  • 8/20/2019 02-OS Concepts View

    24/24

    © CSE-DB 24

    POSIX & Win32 API

    Get the current timeRemove an empty directory

    Create a new directory

    Write data to file

    Read data from file

    Create or open an existing

    file

    Replace the image of aprocess

    Create a new process

    Description

    GetLocalTimetimeRemoveDirectoryrmdir

    CreateDirectorymkdir

    WriteFilewrite

    ReadFileread

    CreateFileopen

    -execve

    CreateProcessfork

    Win32 APIPOSIX