SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Downloaden Sie, um offline zu lesen
System Software for Program Execution:
 User-level View of Operating Systems

      COMP 229 (Section PP) Week 6

          Prof. Richard Zanibbi
          Concordia University
           February 13, 2006
Last Week...
               Supports Programming,
                Efficient System Use
System Software for Program Execution (pp. 1-18)
  Systems and application software (again)
  Resource Abstraction                Applies System Software
  Resource Sharing                          to a Problem


Operating System Strategies (pp. 18-39)                            including
  A brief history of computing and operating systems                 BIOS
       (batch, timesharing, personal, SCC’s, embedded, networks)
  The modern OS as integration/evolution of previous systems


Goals:
  1.    Learn the function and operation of operating systems
  2.    Learn how to exploit OS design during programming (for
        program execution)               “Hacker notes”                        2
Resource Abstractions
  Files
       Represent data on storage devices (e.g. disk)
       Represent data structured as a list


  Abstract Machines
       Represent resources for executing programs
       Program running on abstract machine: a “process”

  Good Abstractions for Programmers:
       Easy to understand
       Provide necessary control (not “too abstract”)
COMP 229-PP (Week 6, Feb. 8)                              3
Resource Sharing
Resource Sharing
  Time-multiplexed: share time on resource (“take turns”, e.g. processor)
  Space-multiplexed: share space on resource (e.g. memory)

Transparent Resource Sharing
  Sharing “invisible” to programmer (done by OS)
  e.g. simulating multiple abstract machines (multiprogramming)

Explicit Resource Sharing
  Programmer requests resource sharing
  e.g. sharing memory between programs

Resource Isolation
  OS permits one process (abstract machine) access to a resource at a time

Security and Consistency Issues
  Prevent problematic or malicious access to resources
                                                                             4
Example

     (Multiprogramming “best case”
      performance, Fig. 1.8)




COMP 229-PP (Week 6, Feb. 8)             5
Operating System Strategies
     OS Strategy
          General characteristics of the programmer’s abstract machine

     Early Days (approx. pre-1960)
          One program at a time, basically no OS

     Strategies
        1. Batch systems: executed non-interactively, multiprogramming
        2. Timesharing systems: multiple users interacting with the system;
           extended multiprogramming, security
        3. Personal Computers, and Workstations: single-user machines;
           multiprogrammed, minimize wait time rather than max. hardware
           use (many had no file system (!); provided by CP/M, MS-DOS)
        4. Embedded systems: guaranteed response times (“real time”)
        5. Small, Communicating Computers (SCC’s): new resource
           management, power management, device management
        6. Network Technology: handle resources, information on networks

COMP 229-PP (Week 6, Feb. 8)                                                  6
This week...
User-Level View of Operating Systems
The Programmer’s Abstract Machine (pp. 42-47)
  Sequential Computation (“single thread”)
  Multithreaded Computation

Process Resources (pp. 47-52)
  esp. files (under UNIX, Windows)

More on Processes and Threads (pp. 52-58)

Writing Concurrent Programs (pp. 58-72)
  Executing Computations
  Executing Commands in UNIX and Windows


Objects (pp. 72-74)
                                                7
The Programmer’s
Abstract Machine
    (pp. 42-52)
Sequential Computation
Algorithm
  A process or set of rules for calculation or problem-solving, esp. with a
   computer (CA Oxford Dictionary)

Sequential algorithms
  Describe a sequence of operations
  Fundamental abstraction for computation

Examples
  Sorting and Search Algorithms
  (e.g. Vol.3,“The Art of Computer Programming” (Donald Knuth))

Algorithms May be Defined Using
  – Natural Language (e.g. English or French)
  – Pseudocode (“informal” operation sequence)
  – Mathematics
     • may not provide an explicit operation sequence
  – As a Source Program in a Programming Language (e.g. C/C++, Java)
     • explicit sequence of operations (unambiguous)                          9
System Calls
     Binary Program
          – Machine-readable translation of source program (e.g.
            “load module”, or executable program (.exe) )
          – Represents explicit machine instructions used to
            implement an algorithm (e.g. op. sequence)


     System Calls in Binary Programs
          – Procedure calls to the system call interface invoke OS
            features (e.g. stop a program, read data from a device)
          – System calls allow the programmer to take advantage
            of resource abstractions and sharing built into the OS

COMP 229-PP (Week 6, Feb. 8)                                          10
What is POSIX?

     Portable Operating System Interface
          Developed to standardize UNIX system call
           interfaces
          POSIX.1: published 1988
          Now used by a large number of UNIXes,
           including Linux
              • Linus Torvalds, Univ. Helsinki, Finland, first
                announced Linux on the Minix newsgroup in 1991



COMP 229-PP (Week 6, Feb. 8)                                     11
Sequential Computation and
            Multiprogramming
Running a Program
  1.   Translate source to binary program (and possibly link)
  2.   Provide program input data, parameters
  3.   Direct OS to start executing instructions from the transfer address
       (“main entry point”) (includes OS calling program loader)
  4.   Program halts when last statement is executed or system call for halt
       (exit()) is made

Execution Engine (part of a process)
  Used by OS to implement multiprogramming
  Status of abstract machine running the process
  Copy of the runtime stack for the process

Runtime Stack
  Used to implement “scopes” in languages (among other things)
  Contains local variables, return addresses, etc.

Fig. 1.2: “Classic” processes (e.g. UNIX)                                      12
Multiprocessing vs. Multithreading
     “Classic” Process
          Sequential program “run” alone on its own abstract machine

     Multiprocessing
          Concurrent execution of processes
          Processes contain separate resource abstractions, binary program copies

     Multithreading
          Thread: another name for “execution engine”
              • “Classic” processes have a single thread
          Multithreading: multiple threads within a single process
          Threads within a process share resources, including binary program

     Example: Fig. 2.6 (Multithreaded process, as found in Windows
      NT/XP, Linux with POSIX threads extension (2.2+))
     Example: Fig 2.3 (“accountant example”)
COMP 229-PP (Week 6, Feb. 8)                                                        13
Implementing Threads
     Example: Java
          Java Virtual Machine (JVM) supports threads
          Thread base class supports threads
          Create subclass of Thread (e.g. MyThread): instances
           define a new thread

     Executing Threads
          – If multiple processors are available, threads may be
            executed in parallel
          – Otherwise (usually) threads share the processor
            (through time-multiplexing)

COMP 229-PP (Week 6, Feb. 8)                                       14
Process Resources

    (pp. 47-52)
OS Management of
   Resources Used by Processes
Resource Allocation
  Threads access resources through system calls
  (insures resource isolation)
  1. Threads must request a resource before use
  2. After request, thread is suspended until resource is allocated to it
     •   while suspended, other threads/processes allocated processor time
  3. After a resource is allocated to a thread, all threads in its
     associated process may share access to the resource (the
     process “owns” the resource)

Memory and Processors
  Traditionally distinguished from other resources
  – Processes/threads (implicitly) request processor when ready
  – When user process is started, loader requests memory from the
     OS to run the program (e.g. user login -> shell -> interaction)
                                                                             16
Resource Descriptors
          – Data structures used to represent physical and
            abstract resources managed by the OS
          – Indicates if resource is available
          – Includes record of which processes are
            currently blocked waiting for the resource

          e.g. file descriptors, process descriptors



COMP 229-PP (Week 6, Feb. 8)                                 17
Files and File Descriptors
     Files
          –   Named, linear stream of bytes stored on a device
          –   Common (default) method for representing data storage
          –   Forms the basis of many other device abstractions
          –   OS maintains record of which files are currently open

     File Lock
          OS preventing processes other than currently allocated from accessing a
           file (e.g. for writing)

     File Descriptor
        OS’s internal representation of file attributes (for file resources)
              • e.g. Indicates if file is locked, or read-only
          UNIX: a non-negative integer (file descriptor (inode) number)
          Windows: “HANDLE”: reference to internal data structure

COMP 229-PP (Week 6, Feb. 8)                                                        18
(Internal) OS Representation of
            Byte Stream Files
                                 Name: Test     (ASCII)
                               Byte     Value
                File Pointer
On file open:                   0     0100 0001 A
(default) pointer set to 0      1     0100 0010 B
Read/Write K bytes:             2     0100 0011 C
Advance pointer by K
                                3     0100 0100 D
Setting File Pointer:           4     0100 0101 E
lseek() (POSIX)
SetFilePointer() (Win)          5     0100 0110 F
No “Type” for Bytes:            6     0100 0111 G
                                                          19
Treated as “raw” bytes
Example: POSIX File System Calls
 System Call                          Effect
 open()        Open file for read or write. OS creates internal
               representation, optionally locks the file. Returns
               a file descriptor (integer), or -1 (error)
 close()       Close file, releasing associated locks and
               resources (e.g. internal representation)
 read()        Read bytes into a buffer. Normally blocks
               (suspends) a process until completion. Returns #
               bytes read, or -1 (error)
 write()       Write bytes from a buffer. Normally blocks
               (suspends) a process until completion.
               Returns # bytes written, or -1 (error)
 lseek()       Set the file pointer location

 fcntl()       (“File Control”): various options to set file
                                                                    20
               attributes (locks, thread blocking, ....)
Rough Equivalences
  for POSIX and Win32 API
 POSIX             Win32
open()    CreateFile()/ OpenFile()
close()   CloseHandle()
read()    ReadFile()
write()   WriteFile()
lseek()   SetFilePointer()



                                     21
Examples

     UNIX file system calls, Fig. 2.4
     Windows file system calls, Fig. 2.5




COMP 229-PP (Week 6, Feb. 8)               22
Using File to Represent Other Resources:
        Devices and Pipes in UNIX
Other Resource Abstractions
  e.g. keyboard, display, memory, processors
  – The more similar these abstractions are, the easier they are for
    programmers to use

UNIX Devices
  Devices are represented as files in the directory tree
  – Devices: located in the /dev directory (e.g. /dev/tty)
  – Devices have open(), close(), read(), write(),
    seek(), fcntl() commands implemented in their drivers
    (similar to file interface)

UNIX Pipes
  Abstract resource allowing processes to communicate by chaining
    outputs to inputs
       e.g. > cat schedule.txt | grep deadline
  – Inputs/outputs are represented using standard files for each
    process (standard input and standard output)                       23
More on Processes and Threads
          (pp. 52-74)
Heavyweight vs. Lightweight Threads

     Heavyweight (“Classic”) Process
          Processes which may contain exactly one thread
           (execution engine)


     Lightweight Process (= “Thread”)
          – A thread (execution engine) within a multithreaded
            process
          – “Light” because each thread does not require the
            overhead of a separate process
     Illustration/Example: Fig. 2.6
COMP 229-PP (Week 6, Feb. 8)                                     25
Thread Representation (Data)
                       in Detail
     Runtime Stack
          Data private to the thread (e.g. local variables)


     Status
          OS data structure: all properties unique to the thread
          – program counter value
          – whether thread is blocked waiting for a resource
          – which resource is being waited for
          – etc.


COMP 229-PP (Week 6, Feb. 8)                                       26
The Move Towards Threads
     Lightweight Processes (Threads)
          Became popular in late 1990’s (esp. w. Java)

     Motivation: Sharing Resources
          – Server managing shared file systems
          – Windowing systems using threads to represent
            individual windows within the physical display

     Example: Fig. 2.7 (window threads)
COMP 229-PP (Week 6, Feb. 8)                                 27
Thread Libraries vs. True Threading
     Thread Libraries (Early 1990’s)
          Used to run threads within heavyweight (“classic”)
           processes (e.g. Mach C thread library)
          OS still implemented classic processes only
          Problem: if one “thread” blocks, then all threads block


       “True” Threading
          OS implements and manages threads independently of
             one another
          If a thread in a multithreaded process blocks, the other
             threads can still execute
COMP 229-PP (Week 6, Feb. 8)                                         28
Creating Processes and Threads
     Initial Process
          – The first process started when machine is turned on
          – Usually the bootstrap loader loading the OS into
            memory


     Creating New Processes and/or Threads
          Done using system calls (i.e. another resource request)
          – If threads are available, separate system calls are used
            for creating threads and creating processes


COMP 229-PP (Week 6, Feb. 8)                                           29
(Initial Process, after turning computer on)

                                Bootstrap Loader
Child Process of                  (Loads OS)                           Parent Process of



                                      OS (UNIX)
                                                                        Sibling Processes

            Login Shell 1            Login Shell 2           Login Shell 3



                                     Bash Shell


                  Email Program                      Web Browser
COMP 229-PP (Week 6, Feb. 8)                                                                30
FORK(), JOIN(), and QUIT()
             System Calls
 (Conway, 1963; Dennis, Van Horne 1966)
Purpose
  Define cooperating sequential processes executing on shared data
  Like threads, processes can share resources (e.g. binary program copy)

FORK(label)
  – Creates a child process that begins execution at “label”
  – Parent (calling) process continues execution after child is created
  – Parent, child are executed concurrently

QUIT()
  Terminates and deallocates (removes) the process issuing the call

JOIN(count)
  – Used to merge processes
  – count is an integer variable shared by a parent and its child processes
  – Locks processor until system call is finished (prevents inconsistency)

                                                                              31
Effect of JOIN(count)


     /* Decrement shared variable */
          count = count – 1;
     /* QUIT unless this is the last process */
          if (count != 0) QUIT();


                     (example provided pp. 56-57)


COMP 229-PP (Week 6, Feb. 8)                        32
Creating “Classic” (Heavyweight)
        Processes (~1970)
Classic Process
 Single-threaded
 Separate resource representation per process
 Each has a separate, private address space


Address Space
 – Physical resources (mainly memory) that can be
   referenced by the execution engine (single thread)
 – Contains stack, status, data, and program (“text”)
 – A memory protection mechanism: prevents writing
   over memory allocated to other processes
                                                        33
Creating “Classic” (Heavyweight) Processes
       Using fork() in POSIX/UNIX
     fork()
          Creates new process
          Child is given copy of current address space
          Parent and child address spaces are separate
              • e.g. changing a variable in the child process does
                not change the variable’s value for the parent


     Process Communication In UNIX
          Only permitted through open files
COMP 229-PP (Week 6, Feb. 8)                                         34
Example: Creating a new process using
                fork()
     1. fork() instruction is executed, causing
        a system call
     2. OS copies data (including address
        space) from the original process to
        the child process
     3. The child process starts execution at
        the instruction following the fork()
        instruction

COMP 229-PP (Week 6, Feb. 8)                      35
Creating Modern and (Lightweight)
           Processes
Creating Modern Process
  – Created by system call from a thread
  – Child created with separate address space, resources
  – A base thread must be created to execute the process
      e.g. CreateProcess() in Windows API

Threads Creating Child Threads within a Process
  – Again, using a system call from a thread
  – Similar to Conway FORK(): child thread runs within the
    process containing the parent thread
  – Child thread has stack and status separate from parent
      e.g. CreateThread() in Windows API
                                                             36
Example: Creating a New Thread
             in a Modern Process
     1. CreateThread(...) is executed
              •     NOTE: unlike fork(), CreateThread() has many
                    parameters
     2. OS creates thread data within the
        process address space (i.e. within the
        same process)
     3. OS starts execution of child thread at
        the indicated starting point

COMP 229-PP (Week 6, Feb. 8)                                       37
Writing Concurrent Programs

         (pp. 58-72)
Multiple Single-Threaded Processes:
               the UNIX Model
     Unix Process Behaviour Defined By
          Text segment (program instructions)
          Data segment (static program data)
          Stack segment (run-time stack: local variables)
          *located in the address space

     UNIX Executable (Binary) Programs
          Compiled/Linked programs define the text, data, and stack
           segments (“a.out”)


     Example: Class UNIX processes (Fig. 2.10)
          Note that the address space contains the Status, Stack Segment,
          Text Segment, and Data Segment
COMP 229-PP (Week 6, Feb. 8)                                                39
Process Descriptors and
             Context Switching
Process Descriptor
 OS Data Structure representing process attributes, incl.:
   • PID: Process Identifier (a reference to the process descriptor)
         – UNIX: PID is integer index for OS-internal table of process descr’s
   •   User that created the process
   •   Parent, Sibling, and Child processes
   •   Resources held by process (e.g. file descriptor references)
   •   Address space for the process
   •   Threads within process
   •   State and Stack Location (in memory) (for classic process)


Context Switching
 Refers to switching the active process and/or thread
 May involve swapping a process/thread out of memory
  and storing it on a device (e.g. disk), among other ops.                       40
UNIX Process Commands
     “ps” command
          – Lists process identifiers (PID) for the user
          – “ps –aux”: lists all processes in the system


     int fork()
          – Returns PID of child process to the parent
          – Returns 0 to child process
          – Child given copy of text, data, stack segments, access
            to all open file resources
          – Parent process descriptor also copied
          – The next process run may be the child, parent, or
            some other process
COMP 229-PP (Week 6, Feb. 8)                                         41
fork() Examples
  Example 1: What do the parent and child output?
       theChild = fork()
       printf(“My PID is %dn”,theChild)


  Example 2: Directing child process execution
       childPID = fork()
       if (theChild == 0) {
           /* child executes here */
           codeForTheChild();
           exit(0);   // Important!
       }
       /* Parent executes here */
       ...

COMP 229-PP (Week 6, Feb. 8)                        42
Changing Program Data Dynamically:
            execve()
int execve(char *path,char *argv[],char *envp[]);
                 program     arguments        environment
                                               variables
Effect of execve()
  – Replaces text, data, and stack areas using the program
    loader
  – After loading, stack is cleared, variables initialized
  – Program is started (call does not return)

System Calls to Wait for Child Process to Stop:
  wait(): block until any child process terminates
  waitpid(P): block until child process with PID P terminates
                                                                43
Multiple Modern Processes
           (e.g. Windows)
Process Creation (CreateProcess())
 Flexible: many more parameters than in fork() (10!)
 Base process can start anywhere in program code
 Returns two resource descriptor references:
   • one for the new process
   • one for the new base thread


Thread Creation (CreateThread())
 Again, flexible, this time with 6 parameters
 A thread may create a sibling thread

  (see text pp. 66-67 for function signatures, discussion)
                                                             44
Executing Commands in
                   UNIX and Windows Shells
     Fatal Errors
          Unrecoverable process errors
              • e.g. trying to write outside a processes’ address space


     System Shells
          Users needs to be able to execute any program,
           however buggy, but without crashing the shell


     Solution:
          Create a child process to execute each command
              • e.g. using fork() or CreateProcess()
COMP 229-PP (Week 6, Feb. 8)                                              45
Objects

(pp. 72-73)
Objects: Another Abstraction
Objects
  – Originally used to represent independent “computation units” in
    simulations; similar to a small process (e.g. workflow simulation)
  – Have private data and operations, along with message passing
    operations (e.g. get/set operations)
  – Can be used to represent a coordinated execution of distributed
    computational units (as was common in simulations)

Classes
  – Simula 67: introduces notion of classes to define object
    behaviour (similar to programs for threads/processes)
  – First widespread application: interfaces (e.g. InterViews, 1989)
  – Java: OS calls into the Java Virtual Machine (JVM), which runs
    on top of the native OS (a simulation in an abstract machine!)
  – OS may be designed to support efficient object implementations
  – Early attempts at “pure” OO operating systems: efficiency issues
                                                                         47
Windows NT/2000/XP
                          Kernel and Objects
     Primitive OS Components
          Defined as objects
          Implemented as C functions: no language inheritance


     Threads
          – Creating a thread generates a kernel Dispatcher
            Object, which then has additional status fields specific
            to threads added (“pseudo inheritence”)
          – This approach allows Kernel operations to be applied
            uniformly to a broad class of abstract data types

COMP 229-PP (Week 6, Feb. 8)                                           48
Summary
• Classic Processes (e.g. in “Old” UNIX)
• Multithreaded Processes (e.g. in Linux,
  Windows)
• Creating Processes and Threads
• Resource Descriptors (file and process)
• Resource Management
• File (e.g. open()) and Process (e.g. fork(),
  CreateThread()) System Calls
• Overview of Writing Concurrent Programs
• Objects and Operating Systems                  49
Next Week...

     Operating Systems Organization
          pages 89-110


     Process Management
          pages 197-206




COMP 229-PP (Week 6, Feb. 8)                  50

Weitere ähnliche Inhalte

Was ist angesagt?

Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/CoreShay Cohen
 
Linux kernel architecture
Linux kernel architectureLinux kernel architecture
Linux kernel architectureSHAJANA BASHEER
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and PropertiesSaadi Rahman
 
Know thyubuntu
Know thyubuntuKnow thyubuntu
Know thyubuntuchkmao
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3WE-IT TUTORIALS
 
Unix Internals OS Architecture
Unix Internals OS ArchitectureUnix Internals OS Architecture
Unix Internals OS ArchitectureKhader Shaik
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linuxMazenetsolution
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernelguest547d74
 
Intro to linux systems administration
Intro to linux systems administrationIntro to linux systems administration
Intro to linux systems administrationPadam Banthia
 
Linux internal
Linux internalLinux internal
Linux internalmcganesh
 

Was ist angesagt? (19)

Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 
Studies
StudiesStudies
Studies
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
 
Linux kernel architecture
Linux kernel architectureLinux kernel architecture
Linux kernel architecture
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
 
Know thyubuntu
Know thyubuntuKnow thyubuntu
Know thyubuntu
 
Ch1 linux basics
Ch1 linux basicsCh1 linux basics
Ch1 linux basics
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Chapter 1: Introduction to Unix / Linux Kernel
Chapter 1: Introduction to Unix / Linux KernelChapter 1: Introduction to Unix / Linux Kernel
Chapter 1: Introduction to Unix / Linux Kernel
 
Case study
Case studyCase study
Case study
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
 
Unix Internals OS Architecture
Unix Internals OS ArchitectureUnix Internals OS Architecture
Unix Internals OS Architecture
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linux
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernel
 
Intro to linux systems administration
Intro to linux systems administrationIntro to linux systems administration
Intro to linux systems administration
 
Linux internal
Linux internalLinux internal
Linux internal
 
OSCh20
OSCh20OSCh20
OSCh20
 
File systems for Embedded Linux
File systems for Embedded LinuxFile systems for Embedded Linux
File systems for Embedded Linux
 

Ähnlich wie User level view of os

Os organization
Os organizationOs organization
Os organizationMohd Arif
 
Process management
Process managementProcess management
Process managementMohd Arif
 
Operating Systems Presentation
Operating Systems Presentation Operating Systems Presentation
Operating Systems Presentation Mayank Thanki
 
Operating systems11 9-07
Operating systems11 9-07Operating systems11 9-07
Operating systems11 9-07anishamca
 
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya JyothiIntroduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya JyothiSowmya Jyothi
 
Operating systems11 9-07
Operating systems11 9-07Operating systems11 9-07
Operating systems11 9-07ainfara
 
Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2mona_hakmy
 
Operating System 4
Operating System 4Operating System 4
Operating System 4tech2click
 
Linux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and TroubleshootingLinux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and TroubleshootingJérôme Kehrli
 
Section02-Structures.ppt
Section02-Structures.pptSection02-Structures.ppt
Section02-Structures.pptJamelPandiin2
 
UNIX INTERNALS UNIT-I
UNIX INTERNALS UNIT-IUNIX INTERNALS UNIT-I
UNIX INTERNALS UNIT-IJK Knowledge
 
OS UNIT 1 PPT.pptx
OS UNIT 1 PPT.pptxOS UNIT 1 PPT.pptx
OS UNIT 1 PPT.pptxPRABAVATHIH
 
MELJUN CORTES operating_system_structure
MELJUN CORTES operating_system_structureMELJUN CORTES operating_system_structure
MELJUN CORTES operating_system_structureMELJUN CORTES
 
Itk rawa t____operatingsystems2
Itk rawa t____operatingsystems2Itk rawa t____operatingsystems2
Itk rawa t____operatingsystems2KapiL RawaT
 

Ähnlich wie User level view of os (20)

Os organization
Os organizationOs organization
Os organization
 
Process management
Process managementProcess management
Process management
 
App A
App AApp A
App A
 
File
FileFile
File
 
Operating Systems Presentation
Operating Systems Presentation Operating Systems Presentation
Operating Systems Presentation
 
Unix case-study
Unix case-studyUnix case-study
Unix case-study
 
Operating systems11 9-07
Operating systems11 9-07Operating systems11 9-07
Operating systems11 9-07
 
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya JyothiIntroduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
 
Operating systems11 9-07
Operating systems11 9-07Operating systems11 9-07
Operating systems11 9-07
 
Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
 
Linux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and TroubleshootingLinux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and Troubleshooting
 
Section02-Structures.ppt
Section02-Structures.pptSection02-Structures.ppt
Section02-Structures.ppt
 
Cs1 3-operating systems
Cs1 3-operating systemsCs1 3-operating systems
Cs1 3-operating systems
 
Spsl unit1
Spsl   unit1Spsl   unit1
Spsl unit1
 
Operating system
Operating systemOperating system
Operating system
 
UNIX INTERNALS UNIT-I
UNIX INTERNALS UNIT-IUNIX INTERNALS UNIT-I
UNIX INTERNALS UNIT-I
 
OS UNIT 1 PPT.pptx
OS UNIT 1 PPT.pptxOS UNIT 1 PPT.pptx
OS UNIT 1 PPT.pptx
 
MELJUN CORTES operating_system_structure
MELJUN CORTES operating_system_structureMELJUN CORTES operating_system_structure
MELJUN CORTES operating_system_structure
 
Itk rawa t____operatingsystems2
Itk rawa t____operatingsystems2Itk rawa t____operatingsystems2
Itk rawa t____operatingsystems2
 

Mehr von Mohd Arif

Bootp and dhcp
Bootp and dhcpBootp and dhcp
Bootp and dhcpMohd Arif
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarpMohd Arif
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocolMohd Arif
 
Project identification
Project identificationProject identification
Project identificationMohd Arif
 
Project evalaution techniques
Project evalaution techniquesProject evalaution techniques
Project evalaution techniquesMohd Arif
 
Presentation
PresentationPresentation
PresentationMohd Arif
 
Pointers in c
Pointers in cPointers in c
Pointers in cMohd Arif
 
Peer to-peer
Peer to-peerPeer to-peer
Peer to-peerMohd Arif
 
Overview of current communications systems
Overview of current communications systemsOverview of current communications systems
Overview of current communications systemsMohd Arif
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdpMohd Arif
 
Objectives of budgeting
Objectives of budgetingObjectives of budgeting
Objectives of budgetingMohd Arif
 
Network management
Network managementNetwork management
Network managementMohd Arif
 
Networing basics
Networing basicsNetworing basics
Networing basicsMohd Arif
 
Iris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformIris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformMohd Arif
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and sslMohd Arif
 
Ip security in i psec
Ip security in i psecIp security in i psec
Ip security in i psecMohd Arif
 
Intro to comp. hardware
Intro to comp. hardwareIntro to comp. hardware
Intro to comp. hardwareMohd Arif
 

Mehr von Mohd Arif (20)

Bootp and dhcp
Bootp and dhcpBootp and dhcp
Bootp and dhcp
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarp
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
 
Project identification
Project identificationProject identification
Project identification
 
Project evalaution techniques
Project evalaution techniquesProject evalaution techniques
Project evalaution techniques
 
Presentation
PresentationPresentation
Presentation
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Peer to-peer
Peer to-peerPeer to-peer
Peer to-peer
 
Overview of current communications systems
Overview of current communications systemsOverview of current communications systems
Overview of current communications systems
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
 
Objectives of budgeting
Objectives of budgetingObjectives of budgeting
Objectives of budgeting
 
Network management
Network managementNetwork management
Network management
 
Networing basics
Networing basicsNetworing basics
Networing basics
 
Loaders
LoadersLoaders
Loaders
 
Lists
ListsLists
Lists
 
Iris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformIris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platform
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and ssl
 
Ip security in i psec
Ip security in i psecIp security in i psec
Ip security in i psec
 
Intro to comp. hardware
Intro to comp. hardwareIntro to comp. hardware
Intro to comp. hardware
 
Heap sort
Heap sortHeap sort
Heap sort
 

Kürzlich hochgeladen

Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 

Kürzlich hochgeladen (20)

Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 

User level view of os

  • 1. System Software for Program Execution: User-level View of Operating Systems COMP 229 (Section PP) Week 6 Prof. Richard Zanibbi Concordia University February 13, 2006
  • 2. Last Week... Supports Programming, Efficient System Use System Software for Program Execution (pp. 1-18) Systems and application software (again) Resource Abstraction Applies System Software Resource Sharing to a Problem Operating System Strategies (pp. 18-39) including A brief history of computing and operating systems BIOS (batch, timesharing, personal, SCC’s, embedded, networks) The modern OS as integration/evolution of previous systems Goals: 1. Learn the function and operation of operating systems 2. Learn how to exploit OS design during programming (for program execution) “Hacker notes” 2
  • 3. Resource Abstractions Files Represent data on storage devices (e.g. disk) Represent data structured as a list Abstract Machines Represent resources for executing programs Program running on abstract machine: a “process” Good Abstractions for Programmers: Easy to understand Provide necessary control (not “too abstract”) COMP 229-PP (Week 6, Feb. 8) 3
  • 4. Resource Sharing Resource Sharing Time-multiplexed: share time on resource (“take turns”, e.g. processor) Space-multiplexed: share space on resource (e.g. memory) Transparent Resource Sharing Sharing “invisible” to programmer (done by OS) e.g. simulating multiple abstract machines (multiprogramming) Explicit Resource Sharing Programmer requests resource sharing e.g. sharing memory between programs Resource Isolation OS permits one process (abstract machine) access to a resource at a time Security and Consistency Issues Prevent problematic or malicious access to resources 4
  • 5. Example (Multiprogramming “best case” performance, Fig. 1.8) COMP 229-PP (Week 6, Feb. 8) 5
  • 6. Operating System Strategies OS Strategy General characteristics of the programmer’s abstract machine Early Days (approx. pre-1960) One program at a time, basically no OS Strategies 1. Batch systems: executed non-interactively, multiprogramming 2. Timesharing systems: multiple users interacting with the system; extended multiprogramming, security 3. Personal Computers, and Workstations: single-user machines; multiprogrammed, minimize wait time rather than max. hardware use (many had no file system (!); provided by CP/M, MS-DOS) 4. Embedded systems: guaranteed response times (“real time”) 5. Small, Communicating Computers (SCC’s): new resource management, power management, device management 6. Network Technology: handle resources, information on networks COMP 229-PP (Week 6, Feb. 8) 6
  • 7. This week... User-Level View of Operating Systems The Programmer’s Abstract Machine (pp. 42-47) Sequential Computation (“single thread”) Multithreaded Computation Process Resources (pp. 47-52) esp. files (under UNIX, Windows) More on Processes and Threads (pp. 52-58) Writing Concurrent Programs (pp. 58-72) Executing Computations Executing Commands in UNIX and Windows Objects (pp. 72-74) 7
  • 9. Sequential Computation Algorithm A process or set of rules for calculation or problem-solving, esp. with a computer (CA Oxford Dictionary) Sequential algorithms Describe a sequence of operations Fundamental abstraction for computation Examples Sorting and Search Algorithms (e.g. Vol.3,“The Art of Computer Programming” (Donald Knuth)) Algorithms May be Defined Using – Natural Language (e.g. English or French) – Pseudocode (“informal” operation sequence) – Mathematics • may not provide an explicit operation sequence – As a Source Program in a Programming Language (e.g. C/C++, Java) • explicit sequence of operations (unambiguous) 9
  • 10. System Calls Binary Program – Machine-readable translation of source program (e.g. “load module”, or executable program (.exe) ) – Represents explicit machine instructions used to implement an algorithm (e.g. op. sequence) System Calls in Binary Programs – Procedure calls to the system call interface invoke OS features (e.g. stop a program, read data from a device) – System calls allow the programmer to take advantage of resource abstractions and sharing built into the OS COMP 229-PP (Week 6, Feb. 8) 10
  • 11. What is POSIX? Portable Operating System Interface Developed to standardize UNIX system call interfaces POSIX.1: published 1988 Now used by a large number of UNIXes, including Linux • Linus Torvalds, Univ. Helsinki, Finland, first announced Linux on the Minix newsgroup in 1991 COMP 229-PP (Week 6, Feb. 8) 11
  • 12. Sequential Computation and Multiprogramming Running a Program 1. Translate source to binary program (and possibly link) 2. Provide program input data, parameters 3. Direct OS to start executing instructions from the transfer address (“main entry point”) (includes OS calling program loader) 4. Program halts when last statement is executed or system call for halt (exit()) is made Execution Engine (part of a process) Used by OS to implement multiprogramming Status of abstract machine running the process Copy of the runtime stack for the process Runtime Stack Used to implement “scopes” in languages (among other things) Contains local variables, return addresses, etc. Fig. 1.2: “Classic” processes (e.g. UNIX) 12
  • 13. Multiprocessing vs. Multithreading “Classic” Process Sequential program “run” alone on its own abstract machine Multiprocessing Concurrent execution of processes Processes contain separate resource abstractions, binary program copies Multithreading Thread: another name for “execution engine” • “Classic” processes have a single thread Multithreading: multiple threads within a single process Threads within a process share resources, including binary program Example: Fig. 2.6 (Multithreaded process, as found in Windows NT/XP, Linux with POSIX threads extension (2.2+)) Example: Fig 2.3 (“accountant example”) COMP 229-PP (Week 6, Feb. 8) 13
  • 14. Implementing Threads Example: Java Java Virtual Machine (JVM) supports threads Thread base class supports threads Create subclass of Thread (e.g. MyThread): instances define a new thread Executing Threads – If multiple processors are available, threads may be executed in parallel – Otherwise (usually) threads share the processor (through time-multiplexing) COMP 229-PP (Week 6, Feb. 8) 14
  • 15. Process Resources (pp. 47-52)
  • 16. OS Management of Resources Used by Processes Resource Allocation Threads access resources through system calls (insures resource isolation) 1. Threads must request a resource before use 2. After request, thread is suspended until resource is allocated to it • while suspended, other threads/processes allocated processor time 3. After a resource is allocated to a thread, all threads in its associated process may share access to the resource (the process “owns” the resource) Memory and Processors Traditionally distinguished from other resources – Processes/threads (implicitly) request processor when ready – When user process is started, loader requests memory from the OS to run the program (e.g. user login -> shell -> interaction) 16
  • 17. Resource Descriptors – Data structures used to represent physical and abstract resources managed by the OS – Indicates if resource is available – Includes record of which processes are currently blocked waiting for the resource e.g. file descriptors, process descriptors COMP 229-PP (Week 6, Feb. 8) 17
  • 18. Files and File Descriptors Files – Named, linear stream of bytes stored on a device – Common (default) method for representing data storage – Forms the basis of many other device abstractions – OS maintains record of which files are currently open File Lock OS preventing processes other than currently allocated from accessing a file (e.g. for writing) File Descriptor OS’s internal representation of file attributes (for file resources) • e.g. Indicates if file is locked, or read-only UNIX: a non-negative integer (file descriptor (inode) number) Windows: “HANDLE”: reference to internal data structure COMP 229-PP (Week 6, Feb. 8) 18
  • 19. (Internal) OS Representation of Byte Stream Files Name: Test (ASCII) Byte Value File Pointer On file open: 0 0100 0001 A (default) pointer set to 0 1 0100 0010 B Read/Write K bytes: 2 0100 0011 C Advance pointer by K 3 0100 0100 D Setting File Pointer: 4 0100 0101 E lseek() (POSIX) SetFilePointer() (Win) 5 0100 0110 F No “Type” for Bytes: 6 0100 0111 G 19 Treated as “raw” bytes
  • 20. Example: POSIX File System Calls System Call Effect open() Open file for read or write. OS creates internal representation, optionally locks the file. Returns a file descriptor (integer), or -1 (error) close() Close file, releasing associated locks and resources (e.g. internal representation) read() Read bytes into a buffer. Normally blocks (suspends) a process until completion. Returns # bytes read, or -1 (error) write() Write bytes from a buffer. Normally blocks (suspends) a process until completion. Returns # bytes written, or -1 (error) lseek() Set the file pointer location fcntl() (“File Control”): various options to set file 20 attributes (locks, thread blocking, ....)
  • 21. Rough Equivalences for POSIX and Win32 API POSIX Win32 open() CreateFile()/ OpenFile() close() CloseHandle() read() ReadFile() write() WriteFile() lseek() SetFilePointer() 21
  • 22. Examples UNIX file system calls, Fig. 2.4 Windows file system calls, Fig. 2.5 COMP 229-PP (Week 6, Feb. 8) 22
  • 23. Using File to Represent Other Resources: Devices and Pipes in UNIX Other Resource Abstractions e.g. keyboard, display, memory, processors – The more similar these abstractions are, the easier they are for programmers to use UNIX Devices Devices are represented as files in the directory tree – Devices: located in the /dev directory (e.g. /dev/tty) – Devices have open(), close(), read(), write(), seek(), fcntl() commands implemented in their drivers (similar to file interface) UNIX Pipes Abstract resource allowing processes to communicate by chaining outputs to inputs e.g. > cat schedule.txt | grep deadline – Inputs/outputs are represented using standard files for each process (standard input and standard output) 23
  • 24. More on Processes and Threads (pp. 52-74)
  • 25. Heavyweight vs. Lightweight Threads Heavyweight (“Classic”) Process Processes which may contain exactly one thread (execution engine) Lightweight Process (= “Thread”) – A thread (execution engine) within a multithreaded process – “Light” because each thread does not require the overhead of a separate process Illustration/Example: Fig. 2.6 COMP 229-PP (Week 6, Feb. 8) 25
  • 26. Thread Representation (Data) in Detail Runtime Stack Data private to the thread (e.g. local variables) Status OS data structure: all properties unique to the thread – program counter value – whether thread is blocked waiting for a resource – which resource is being waited for – etc. COMP 229-PP (Week 6, Feb. 8) 26
  • 27. The Move Towards Threads Lightweight Processes (Threads) Became popular in late 1990’s (esp. w. Java) Motivation: Sharing Resources – Server managing shared file systems – Windowing systems using threads to represent individual windows within the physical display Example: Fig. 2.7 (window threads) COMP 229-PP (Week 6, Feb. 8) 27
  • 28. Thread Libraries vs. True Threading Thread Libraries (Early 1990’s) Used to run threads within heavyweight (“classic”) processes (e.g. Mach C thread library) OS still implemented classic processes only Problem: if one “thread” blocks, then all threads block “True” Threading OS implements and manages threads independently of one another If a thread in a multithreaded process blocks, the other threads can still execute COMP 229-PP (Week 6, Feb. 8) 28
  • 29. Creating Processes and Threads Initial Process – The first process started when machine is turned on – Usually the bootstrap loader loading the OS into memory Creating New Processes and/or Threads Done using system calls (i.e. another resource request) – If threads are available, separate system calls are used for creating threads and creating processes COMP 229-PP (Week 6, Feb. 8) 29
  • 30. (Initial Process, after turning computer on) Bootstrap Loader Child Process of (Loads OS) Parent Process of OS (UNIX) Sibling Processes Login Shell 1 Login Shell 2 Login Shell 3 Bash Shell Email Program Web Browser COMP 229-PP (Week 6, Feb. 8) 30
  • 31. FORK(), JOIN(), and QUIT() System Calls (Conway, 1963; Dennis, Van Horne 1966) Purpose Define cooperating sequential processes executing on shared data Like threads, processes can share resources (e.g. binary program copy) FORK(label) – Creates a child process that begins execution at “label” – Parent (calling) process continues execution after child is created – Parent, child are executed concurrently QUIT() Terminates and deallocates (removes) the process issuing the call JOIN(count) – Used to merge processes – count is an integer variable shared by a parent and its child processes – Locks processor until system call is finished (prevents inconsistency) 31
  • 32. Effect of JOIN(count) /* Decrement shared variable */ count = count – 1; /* QUIT unless this is the last process */ if (count != 0) QUIT(); (example provided pp. 56-57) COMP 229-PP (Week 6, Feb. 8) 32
  • 33. Creating “Classic” (Heavyweight) Processes (~1970) Classic Process Single-threaded Separate resource representation per process Each has a separate, private address space Address Space – Physical resources (mainly memory) that can be referenced by the execution engine (single thread) – Contains stack, status, data, and program (“text”) – A memory protection mechanism: prevents writing over memory allocated to other processes 33
  • 34. Creating “Classic” (Heavyweight) Processes Using fork() in POSIX/UNIX fork() Creates new process Child is given copy of current address space Parent and child address spaces are separate • e.g. changing a variable in the child process does not change the variable’s value for the parent Process Communication In UNIX Only permitted through open files COMP 229-PP (Week 6, Feb. 8) 34
  • 35. Example: Creating a new process using fork() 1. fork() instruction is executed, causing a system call 2. OS copies data (including address space) from the original process to the child process 3. The child process starts execution at the instruction following the fork() instruction COMP 229-PP (Week 6, Feb. 8) 35
  • 36. Creating Modern and (Lightweight) Processes Creating Modern Process – Created by system call from a thread – Child created with separate address space, resources – A base thread must be created to execute the process e.g. CreateProcess() in Windows API Threads Creating Child Threads within a Process – Again, using a system call from a thread – Similar to Conway FORK(): child thread runs within the process containing the parent thread – Child thread has stack and status separate from parent e.g. CreateThread() in Windows API 36
  • 37. Example: Creating a New Thread in a Modern Process 1. CreateThread(...) is executed • NOTE: unlike fork(), CreateThread() has many parameters 2. OS creates thread data within the process address space (i.e. within the same process) 3. OS starts execution of child thread at the indicated starting point COMP 229-PP (Week 6, Feb. 8) 37
  • 39. Multiple Single-Threaded Processes: the UNIX Model Unix Process Behaviour Defined By Text segment (program instructions) Data segment (static program data) Stack segment (run-time stack: local variables) *located in the address space UNIX Executable (Binary) Programs Compiled/Linked programs define the text, data, and stack segments (“a.out”) Example: Class UNIX processes (Fig. 2.10) Note that the address space contains the Status, Stack Segment, Text Segment, and Data Segment COMP 229-PP (Week 6, Feb. 8) 39
  • 40. Process Descriptors and Context Switching Process Descriptor OS Data Structure representing process attributes, incl.: • PID: Process Identifier (a reference to the process descriptor) – UNIX: PID is integer index for OS-internal table of process descr’s • User that created the process • Parent, Sibling, and Child processes • Resources held by process (e.g. file descriptor references) • Address space for the process • Threads within process • State and Stack Location (in memory) (for classic process) Context Switching Refers to switching the active process and/or thread May involve swapping a process/thread out of memory and storing it on a device (e.g. disk), among other ops. 40
  • 41. UNIX Process Commands “ps” command – Lists process identifiers (PID) for the user – “ps –aux”: lists all processes in the system int fork() – Returns PID of child process to the parent – Returns 0 to child process – Child given copy of text, data, stack segments, access to all open file resources – Parent process descriptor also copied – The next process run may be the child, parent, or some other process COMP 229-PP (Week 6, Feb. 8) 41
  • 42. fork() Examples Example 1: What do the parent and child output? theChild = fork() printf(“My PID is %dn”,theChild) Example 2: Directing child process execution childPID = fork() if (theChild == 0) { /* child executes here */ codeForTheChild(); exit(0); // Important! } /* Parent executes here */ ... COMP 229-PP (Week 6, Feb. 8) 42
  • 43. Changing Program Data Dynamically: execve() int execve(char *path,char *argv[],char *envp[]); program arguments environment variables Effect of execve() – Replaces text, data, and stack areas using the program loader – After loading, stack is cleared, variables initialized – Program is started (call does not return) System Calls to Wait for Child Process to Stop: wait(): block until any child process terminates waitpid(P): block until child process with PID P terminates 43
  • 44. Multiple Modern Processes (e.g. Windows) Process Creation (CreateProcess()) Flexible: many more parameters than in fork() (10!) Base process can start anywhere in program code Returns two resource descriptor references: • one for the new process • one for the new base thread Thread Creation (CreateThread()) Again, flexible, this time with 6 parameters A thread may create a sibling thread (see text pp. 66-67 for function signatures, discussion) 44
  • 45. Executing Commands in UNIX and Windows Shells Fatal Errors Unrecoverable process errors • e.g. trying to write outside a processes’ address space System Shells Users needs to be able to execute any program, however buggy, but without crashing the shell Solution: Create a child process to execute each command • e.g. using fork() or CreateProcess() COMP 229-PP (Week 6, Feb. 8) 45
  • 47. Objects: Another Abstraction Objects – Originally used to represent independent “computation units” in simulations; similar to a small process (e.g. workflow simulation) – Have private data and operations, along with message passing operations (e.g. get/set operations) – Can be used to represent a coordinated execution of distributed computational units (as was common in simulations) Classes – Simula 67: introduces notion of classes to define object behaviour (similar to programs for threads/processes) – First widespread application: interfaces (e.g. InterViews, 1989) – Java: OS calls into the Java Virtual Machine (JVM), which runs on top of the native OS (a simulation in an abstract machine!) – OS may be designed to support efficient object implementations – Early attempts at “pure” OO operating systems: efficiency issues 47
  • 48. Windows NT/2000/XP Kernel and Objects Primitive OS Components Defined as objects Implemented as C functions: no language inheritance Threads – Creating a thread generates a kernel Dispatcher Object, which then has additional status fields specific to threads added (“pseudo inheritence”) – This approach allows Kernel operations to be applied uniformly to a broad class of abstract data types COMP 229-PP (Week 6, Feb. 8) 48
  • 49. Summary • Classic Processes (e.g. in “Old” UNIX) • Multithreaded Processes (e.g. in Linux, Windows) • Creating Processes and Threads • Resource Descriptors (file and process) • Resource Management • File (e.g. open()) and Process (e.g. fork(), CreateThread()) System Calls • Overview of Writing Concurrent Programs • Objects and Operating Systems 49
  • 50. Next Week... Operating Systems Organization pages 89-110 Process Management pages 197-206 COMP 229-PP (Week 6, Feb. 8) 50