Process API

OS - Ch 5

Reference : http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-api.pdf

Process API

  • Unix uses for() and exec() system call to create a process.

  • What kind of interface does OS provide to create and control process?

Fork()

  • forked process starts where it is called (not from the beginning)
  • Child process:
    • has Different address space, register and its own PC from its parent process.

fork() system call return value is different. Parent process gets child PID as its return, childe process gets 0.
This difference allows programmer to easily code the program that child and parent execute different code.

  • The execution order of processes may differ (non-determinism).

Wait()

  • In case when the parent process has to wait for its child processes.
  • Once every child process finishes, it returns.

Exec()

  • System call to run another process (not oneself)
  • Input: file name (program), inputs –> read the static data and program code, and overwrite the current process’s code segment and static data section.
    • For the new program, it resets heap, stack, and space addresses and so on.
    • At the given example, the child process becomes the new process (It still is a child process).
      • IT DOES NOT create a new process

Process

OS - Ch 3,4

Reference : http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf

Process

  • Process is a running program.

  • Virtualization runs multiple processes by turns, hence providing a virtual environment that contains multiple number of CPUs

    • Context Switch : run & stop …
    • Modern OS uses time sharing mechanism which lowers each processors performance.
  • Scheduling: OS policy to decide run which program at which point.

    • Scheduling refers to
      • past info: which programs ran for the last one minute
      • workload info: what kind of programs ran
      • performance measure: system tends to increase communication, workload?

Definition

  • Main components of machine states are:
    • Memory: space where instructions and resources are saved/loaded
    • Register:
      • Program Counter: which instruction is being excuted aka instruction pointer
      • Stack pointer: used for managing stack where function varaible and return addresses are saved.

Process API

  • Create: OS needs to provide a way to create new process
    • Shell, double-click…
  • Destroy: Needs to able to forcibly close processes
  • Wait: different kinds of process being waited to take turns (wait interface)
  • Miscellaneous Control: Pause | resume …
  • Status: Interface that provides process status information such as how long has it been running, current stauts…

In-Depth

  • OS steps to run a program
    1. Load program code and static data (initialized variables) into memory (process address space).
      • Early OS loaded both program code and static data before executing a program.
      • Modern OS loads necessary part of it while running a program.
        • Late load requires paging and swapping (later be discussed).
    2. Memory allocation for run-time stack purpose.
      • C uses stack for saving variables, return address…
      • OS resets the stack with given parameters especially by using main() function variables argc and argv vectors.
    3. Memory allocation for heap
      • Heap is for saving dynamically allocated data in C; malloc and free.
      • Heap is used for linked list, hash table, tree. All the different size (dynamic) data structures.
    4. Has three file descriptors - FOR I/O
      • STDIN
      • STDOUT
      • STDERR
    5. Now ready to execute the program
      • Branch to main()

Process Status

  • Running
  • Ready: Process is ready, but OS is not; executing another process.
  • Blocked: Pause the process while waiting for another events; waiting for data

Data Structures

  • Register Context: saves register values when the process stopped.
    • Once process resumes, use the saved values.
  • Process has states such as initial, and final
    • Final state: Process is completed, but remain in the memory; useful for parent process to check if the task given to its child is successfully completed.

Introduction To OS

OS - Ch 1,2

Reference : Operating Systems: Three Easy Pieces, Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau

Introduction To OS

  • OS provides system calls that allow application programs request to use.
    • OS privdes the calss for program execution, memory access, etc
    • Hence also be referred as providing a “standard library”
  • Virtualization allows many programs to share a CPU, and to be executed concurrently.
    • Each program can access to its resourse and instructions.
    • Hence called as a “resource manager”

Virtualization

CPU

  • Logical transformation of a/few CPU/s into a number of it to run many programs concurrently.

Memory

  • Physical memory is an array of byte which has address.
  • Do not forget the insturctions are stored within its memory.
  • Run the same program concurrently
    • It will have the same memory allocation (002000000 in the given example)[^1]
      • Each process has its own virtual address space
      • The actual memory address (physical) is different.

[^1]: Make sure address-space randomization is diabled -> enabled for security reason regarding stack-smashing attacks.

Concurrency

  • It becomes an issue because
    • CPU executes one insturction at a time. Hence, insturctions are not atomic.

Persistence

  • Device like DRAM saves data in volatile^2
    • Disconnection or crash result with data loss.
  • OS software manages disk : file system.
    • Unlike CPU or memory, OS does not do virtualization on disk, but rather assume users may want to share file info.
    • For performance, most File System delays writes, and batch them (try) into larger groups.
    • For persistence, most file system incorporate intricate write protocol such as journaling, or copy-on-write.

Design Goals

  1. Define Abstractaions to ease the usage of computer system
    • Abstraction allows:
      • Able to write codes in C (higher lang) even if you do not know Assembly.
      • Able to write assembly without considering logic gates.
      • Able to write processes without having knowledge in transisters.
  2. Minimize the overhead (performance)
    • Having virtualization and easy-to-use system is meaningful but not necessary.
  3. Safety between OS and Application programs.
    • OS needs to ensure the execution of a program does not negatively influence the others
    • Safety is a key concept of Isolation principle.
  4. Provides high level reliability
    • OS fails, all the applications bulit on fail.
  5. Energy-efficiency, security, mobility and so on…
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×