OS provides process abstraction and OS data structures.How does OS create a process. - Codeprg

Breaking

programing News Travel Computer Engineering Science Blogging Earning

Friday 8 May 2020

OS provides process abstraction and OS data structures.How does OS create a process.

OS provides process abstraction:)

  • When you run an exe file, the OS creates a process = a running program
  • OS timeshares CPU across multiple processes: virtualizes CPU
  • OS has a CPU scheduler that picks one of the many active processes to execute on a CPU.
    – Policy: which process to run
    – Mechanism: how to “context switch” between processes

What constitutes a process:)

  • A unique identifier PID)
  • Memory image
    – Code and data (static)
    – Stack and heap (dynamic)
  • File descriptors
    – Pointers to open files and devices

How does OS create a process?

  • Allocates memory and creates memory image
    – Loads code, data from disk exe,
    – Creates runtime stack, heap
  • Opens basic files – STD IN, OUT, ERR
  • Initializes CPU registers
    – PC points to first instruction

States of a process

Dead: terminated

OS data structures

  • OS maintains a data structure (e.g., list) of all active processes
  • Information about each process is stored in a process control block (PCB).
    – Process identifier
    – Process state
    – Pointers to other related processes (parent)
    – CPU context of the process (saved when the process is suspended)
    – Pointers to memory locations. – Pointers to open files