[OSTEP] 2. The Process

ch3~4: 프로세스의 구성 요소 / 상태 / 구현

Table Of Contents

CH4: The Abstraction: The Process

Virtualizing the CPU: Time sharing

1. The Abstraction: A Process

process

2. Process API

3. Process Creation

how programs are transformed into processes?

  1. load its code and any static data into memory, into the address space of the process.
    • programs initially reside on disk in some kind of executable format
    • the OS read those bytes from disk and place them in memory somewhere
    • In early (or simple) OS : loading process is done eagerly
      • i.e., all at once before running the program
    • In modefn OS: perform the process lazily
      • i.e., by loading pieces of code of data only as they are needed during program execution
      • to unserstand this, concept of paging and swapping is needed
  2. allocate the program's run-time stack (or just stack)
    • the OS allocates memory for local variables, function parameters, and return addresses
    • the OS initialize the stack with arguments: argc and the argv array of main() function
  3. allocate memory for the program's heap
    • heap is used for explicitly requested dynamically-allocated data
      • requested by malloc(), freed by free()
      • linked lists, hash tables, trees, etc.
  4. other initialization tasks
    • I/O setup
      • each process by default has three open file descriptors(standard input, output, error)
  5. start the program running at the entry point(main())

4. Process States

a process can be in one of three states:

  1. Running
    • process is running on a processor.
    • processor is executing instructions.
  2. Ready
    • process is ready to run but for some reason, the OS has chosen not to run it at this given moment.
  3. Blocked
    • process has performed some kind of operation that makes it not ready to run until some other event takes place.
    • i.e., I/O request to a disk

Example

TimeProcess 0Process 1Notes
1RunningReady
2RunningReady
3RunningReady
4RunningReadyProcess 0 now done
5-Running
6-Running
7-Running
8-RunningProcess 1 now done
TimeProcess 0Process 1Notes
1RunningReady
2RunningReady
3RunningReadyProcess 0 initiates I/O
4BlockedRunningProcess 0 is blocked,
5BlockedRunningso Process1 runs
6BlockedRunning
7ReadyRunningI/O done
8ReadyRunningProcess 1 now done
9Running-
10Running-Process 0 now done

5. Data Structures

The OS is a program. Like any program, the OS has some key data structures