Docsity

Understanding Process Management in OS: Processes, Address Space, Creation, Study notes of Computer Science

Partial preview of the text

Download Understanding Process Management in OS: Processes, Address Space, Creation and more Study notes Computer Science in PDF only on Docsity!

Operating SystemsOperating Systems

CMPSC 473 CMPSC 473

Process Management Process Management January 29, 2008 - Lecture January 29, 2008 - Lecture (^44) Instructor: Trent Jaeger Instructor: Trent Jaeger

  • Last class:
    • Operating system structure and basics
  • Today:
    • Process Management

Processes

  • Binary to Process
    • Dynamic State
  • Multiple Processes
    • Context Switch
  • Identify a Process
    • Distinct versions, communication

Overview

  • Questions that we explore
    • How are processes created?
    • How is a process represented and managed?
      • Process creation, process control block
    • How does the OS manage multiple processes?
      • Process state, ownership, scheduling
    • How can processes communicate?
      • Interprocess communication, concurrency, deadlock

Process

  • Address space + threads + resources
  • Address space contains code and data of a process
  • Threads are individual execution contexts
  • Resources are physical support necessary to run the process (memory, disk, …) Text Data

Process Address Space

  • Program (Text)
  • Global Data (Data)
  • Dynamic Data (Heap)
  • Thread-local Data (Stack)
  • Each thread has its own

stack

Program Address Space

  • Text : Immutable code
  • Global Data : Variables allocated with the program
    • Lifetime is entire program
  • Heap : Variables that are dynamically allocated
    • Lifetime is between allocation (malloc) and deallocation (free)
  • Stack : Variables allocated dynamically on the stack
    • Lifetime is function lifetime

Program Address Space

  • Where in a database process’s address space would you allocate? - Database - Record - Query specification

Program to Process

  • Program is stored in a binary format
    • Executable and Linkable Format (ELF)
    • a.out
  • Binary format describes
    • Program sections
      • Text, Data, … (many types of sections)
    • Program segments
      • What to load at execution time
      • One or more sections

ELF Files

  • Source code
    • test.c
  • Compile into an ELF relocatable file
    • test.o (object file)
  • Compile into an ELF shared object file
    • “gcc -shared” >> test.so (from .o files)
  • Compile into an ELF executable file
    • gcc -o test test.c

Load and Run ELF Binaries

  • Program Interpreter is loaded first
    • Guides the loading process by interpreting ELF binaries
    • Segment type PT_INTERP
    • Run by exec
  • Interpreter loads Loadable Segments
    • Contains the program contents: text, global data
    • Segment type PT_LOAD
    • Mapped into the process address space at loadtime (you see these for libraries only)
  • Others are loaded on demand, Dynamic Segment
    • Libraries
    • Segment type PT_DYNAMIC
    • Load of separate library files when needed (you see these in opening of lib files)

ELF Binary View

  • Commands
    • Linux: readelf
    • Solaris: elfdump Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000034 0x08048034 0x08048034 0x000e0 0x000e0 R E 0x INTERP 0x000114 0x08048114 0x08048114 0x00013 0x00013 R 0x [Requesting program interpreter: /lib/ld-linux.so.2] LOAD 0x000000 0x08048000 0x08048000 0x016b8 0x016b8 R E 0x LOAD 0x0016b8 0x0804a6b8 0x0804a6b8 0x00120 0x00160 RW 0x DYNAMIC 0x0016cc 0x0804a6cc 0x0804a6cc 0x000d0 0x000d0 RW 0x NOTE 0x000128 0x08048128 0x08048128 0x00020 0x00020 R 0x GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x ……. Dynamic section at offset 0x16cc contains 21 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libm.so.6] 0x00000001 (NEEDED) Shared library: [libc.so.6]

Executing a Process

What to execute?

  • Program status word
  • Register that stores the program counter
    • Next instruction to be executed
  • Registers store state of execution in CPU
  • Stack pointer
  • Data registers
  • Thread of execution
  • Has its own stack

Executing a Proccess

  • Thread executes over the process’s address space
    • Usually the text segment
  • Until…
    • Time slice expires (timer interrupt)
    • Another event (e.g., interrupt from other device)
    • Exception (oops)
    • System call (switch to kernel mode)