본문 바로가기
코딩이야기/운영체제

04-1.Proceses and Threads - Process concepts

by GiraffeB 2016. 2. 15.
Process and Threads

이 글은 서울대학교 평생교육원 열린강좌 중, 홍성수 교수님의 운영체제 강의 및 pt자료를 정리한 내용임을 알려드립니다. 
서울대학교 평생교육원 열린강좌 - 운영체제 (홍성수 교수님)

Process and Threads

Agenda

  1. Process Concepts
  2. Process Scheduling
  3. Context Switching
  4. Process Creation and Termination
  5. MultiThreading
  6. Conclusion

1. Process concepts

Process Concepts (1)
  • What is a process and why is it useful?

    • 프로세스란, OS위에서 program을 구동시키는 단위.
    • runtime system의 수행주체.
    • 자원사용의 주체.
  • Why?

    • With many things happening at once in a system, need some way of separating them all out cleanly.
    • Important concept : “Decomposition
      • Solve a hard problem by chopping it into serveral simpler problems that can be solved separately.
      • SW의 복잡도를 감소하는 2가지 방법
        • abstraction
        • decomposition : 복잡한 문제를 단순한 여러개로 분할하여 해결하는 방법

Process Concepts (2)
  • What?

    • Definition of a process
      • Program in execution.
      • An execution stream in the context of a particular process state.
      • 특정 프로세스의 상태에서 실행되는 execution stream이다.
    • What is an “execution stream” and what is a “process state”?

      • Process state is everything that can affect, or be affected by the process
        • code, data, values, open files, etc.
      • Execution strea is a sequence of instructions performed in a process state
        • Key simplifying feature of a process
        • Only one thing happens at a time within a process.
    • Execution Stream

      • 프로세스가 지금까지 수행된 모든 명령어들의 순서.
    • Program과 Process의 차이
      • Program이 수행중이라는 것은?
        • 저장매체에 저장된 수동적인 Code Sequence => process
        • cpu, memory, i/o device 등 더 많은 자원을 필요로함. (능동적인)

Process Concepts (3)
  • Process state of context
    • Collection of three types of contexts
      • Memory context
        • code segment, data segment, stack segment, heap
        • code : 기계어
        • data : 프로그램 전역변수
        • stack : 지역변수, function call 등의 정보 저장.
      • Hardware context
        • CPU registers, I/O registers
      • System context
        • Process table, open file table, page table.
    • Realization of the notion of process.

Process Concepts (4)
  • Multiprogramming vs. multiprocessing
    • Uniprogramming
      • Only one process in memory at a time.
      • Mostly old PC OS
      • Makes some parts of OS easier, bu others hard.
    • Multiprogramming
      • memory관점에서 여러개의 active job이 수행되는 것(load 되는것)
      • Multiple processes in memory.
      • Most systems support multiprogramming
    • Multiprocessing
      • Multiple processes are running together at the same time
      • CPU is multiplexed.
    • Swapping
      • 메모리부족 문제를 해결하기 위해,
      • cpu를 사용하지 않는 프로세스의 데이터를 메모리에서 다른 저장장치로 내보내고,
      • cpu를 사용할 프로세스의 데이터를 메모리로 로드하는 것.

Process Concepts (5)
  • Why is the process useful?
  • Design-time entity vs. run-time entity

    • Accepting the system requirements and
    • Generating a collection of tasks
      • Design by decomposition
    • Task is a design-time entity
    • Process is a run-time entity
      • Target of CPU scheduling and resource allocation
    • Implementation is

      • A mapping from design-time entities onto run-time entities.
    • Run-time entity : OS가 관리하는 단위, 수행의 주체, 자원사용의 주체

    • SW system의 개발
      1. 설계 –> 요구사항 명세서 –> 설계 (Decomposition) —> “a set of Task”
      2. 구현 –> {Tasks} –> 구현 –> {Programs} –> “Processes”
        • 설계단계의 Task들이 1:1로 Process로 mapping된다.
        • OS가 Task들을 하나의 Process로 처리가능
    • Process는 실세계의 무엇과 비슷할까?
      • OS가 정부라면, Process는 시민과 유사
      • 수행의 주체 + 자원사용의 주체

Process Control Block
  • With Multiprocessing, OS must keep track of processes
    • For each process, a process control block (PCB) holds
      • Execution state( saved registers, etc. )
      • Scheduling information ( priority )
      • Accounting and other misc, information (open files )
    • System-wide table of PCB
      • Process table
    • UNIX
      • Fixed-size array of PCB’s

State Transition (1)
  • As a process executes, it changes state
    • New
      • Process is being created.
    • Running
      • Instructions are being executed.
    • Waiting
      • Process is waiting for some event to occur
    • Ready
      • Process is waiting to be assigned to CPU
    • Terminated
      • Process has finished execution.

State Transition (3)
  • State transitions and scheduling queues
    • Queues at different state
      • Ready queue(PCB사용)
        • set of all processes residing in main memory. –> cpu를 받지 못함.
          –> Synchrous I/O시 waiting to ready 신호 수신시
          다수의 waiting proess가 있을 수 있음.
          다만 이유가 다를 수 있고,
          각 이유에 따른 queue에 저장됨.
        • ready and waiting to execute
      • Device queues ( I/O waiting queues )
        • Set of processes waiting for an I/O device
    • State transition
      • Migrating processes between various queues.