SlideShare a Scribd company logo
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

More Related Content

What's hot

Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
Shay Cohen
 
Studies
StudiesStudies
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
Nishant Munjal
 
Linux kernel architecture
Linux kernel architectureLinux kernel architecture
Linux kernel architecture
SHAJANA BASHEER
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
Saadi Rahman
 
Know thyubuntu
Know thyubuntuKnow thyubuntu
Know thyubuntu
chkmao
 
Ch1 linux basics
Ch1 linux basicsCh1 linux basics
Ch1 linux basics
chandranath06
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
mcganesh
 
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
Dr.Ashvini Chaudhari Bhongade
 
Case study
Case studyCase study
Case study
Usha Ravichandran
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
Goutam Sahoo
 
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
WE-IT TUTORIALS
 
Unix Internals OS Architecture
Unix Internals OS ArchitectureUnix Internals OS Architecture
Unix Internals OS Architecture
Khader Shaik
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linux
Mazenetsolution
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernel
guest547d74
 
Intro to linux systems administration
Intro to linux systems administrationIntro to linux systems administration
Intro to linux systems administration
Padam Banthia
 
Linux internal
Linux internalLinux internal
Linux internal
mcganesh
 
OSCh20
OSCh20OSCh20
File systems for Embedded Linux
File systems for Embedded LinuxFile systems for Embedded Linux
File systems for Embedded Linux
Emertxe Information Technologies Pvt Ltd
 

What's hot (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
 

Similar to User level view of os

Os organization
Os organizationOs organization
Os organization
Mohd Arif
 
Process management
Process managementProcess management
Process management
Mohd Arif
 
App A
App AApp A
File
FileFile
File
Mohd Arif
 
Operating Systems Presentation
Operating Systems Presentation Operating Systems Presentation
Operating Systems Presentation
Mayank Thanki
 
Unix case-study
Unix case-studyUnix case-study
Unix case-study
NishantMishra126
 
Operating systems11 9-07
Operating systems11 9-07Operating systems11 9-07
Operating systems11 9-07
anishamca
 
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
Sowmya Jyothi
 
Operating systems11 9-07
Operating systems11 9-07Operating systems11 9-07
Operating systems11 9-07
ainfara
 
Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2
mona_hakmy
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
tech2click
 
Linux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and TroubleshootingLinux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and Troubleshooting
Jérôme Kehrli
 
Section02-Structures.ppt
Section02-Structures.pptSection02-Structures.ppt
Section02-Structures.ppt
JamelPandiin2
 
Cs1 3-operating systems
Cs1 3-operating systemsCs1 3-operating systems
Cs1 3-operating systems
maria teresa salta
 
Spsl unit1
Spsl   unit1Spsl   unit1
Spsl unit1
Sasidhar Kothuru
 
Operating system
Operating systemOperating system
Operating system
Tanmay Kataria
 
UNIX INTERNALS UNIT-I
UNIX INTERNALS UNIT-IUNIX INTERNALS UNIT-I
UNIX INTERNALS UNIT-I
JK Knowledge
 
OS UNIT 1 PPT.pptx
OS UNIT 1 PPT.pptxOS UNIT 1 PPT.pptx
OS UNIT 1 PPT.pptx
PRABAVATHIH
 
MELJUN CORTES operating_system_structure
MELJUN CORTES operating_system_structureMELJUN CORTES operating_system_structure
MELJUN CORTES operating_system_structure
MELJUN CORTES
 
Itk rawa t____operatingsystems2
Itk rawa t____operatingsystems2Itk rawa t____operatingsystems2
Itk rawa t____operatingsystems2
KapiL RawaT
 

Similar to 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
 

More from Mohd Arif

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

More from 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
 

Recently uploaded

Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 

Recently uploaded (20)

Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 

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