Operating Systems 101: Virtualisation — Process(i)

E.Y.
3 min readJun 14, 2021

--

Photo by Anna Bratiychuk on Unsplash

This is a course note of an online course I took relating to the Operating System on educative.io.

Operating System and Virtualisation

  • The OS (operating system) transforms a physical resource (e.g.a disk) into a virtual form.

Design goals of OS

  • Abstraction: so that we can focus on high level, e.g. use high-level language e.g. python instead of assembly language, assembly language not logic gates.
  • A balance between high performance and minimum cost
  • Protection & security
  • Reliability

Chapter 1. Process

A running program is a process.

Registers

Registers are the smallest data holding elements that are built into the processor itself. Processor registers are at the top of the memory hierarchy, and provide the fastest way to access data. They store instructions which await to be decoded or executed. Common registers:

  1. PC — program counter — stores address of the -> next <- instruction in RAM
  2. MAR — memory address register — stores the address of the:next address -or next instruction
  3. MDR — memory data register — stores the data that is to be sent to or fetched from memory
  4. CIR — current instruction register — stores actual instruction that is being decoded and executed
  5. ACC — accumulator — stores result of calculations
  6. IR — interrupt register — manages requests from I/O devices

Difference between memory and registers are:

  • Data can be loaded from memory into registers and tasks are handled.
  • Registers hold the instructions that the CPU is currently processing
  • Memory holds the instructions and data that the currently executing program in CPU requires.

Time sharing and Space sharing

In order for OS to virtualise the CPU, it run multi processes concurrently, thus each process taking control of CPU at a time period. This is called time sharing of the CPU.

Space sharing, on the other hand is to share a resource among the parties, e.g. disk space.

Mechanism and Policy

In order for OS to virtualise the CPU, it also need low-level machinery and high-level intelligence. The low-level machinery is mechanisms — low-level methods that implement a specific functionality, e.g. context switch.

The high level intelligence is policies, which are algorithms for making decision regarding running process, e.g. a scheduling policy.

Process API

There are couple process apis.

  • Create
  • Destroy
  • Wait : Wait for a process to stop running.
  • Status checking
  • Others: This varies from OS to OS, e.g. UNIX has pipe.

For UNIX system: the most common/important ones :

  • The fork() system call is used to create a new process. Note this will create a copy of current process.
  • The wait() is for a parent to wait for a child process to finish.
  • The exec() is different from fork() in that it transforms current process by loading executable from another program and overwrites its current code segment, and the heap, stack and other memory space of the running process are re-initialised.

Preparation to start a process

  • OS loads the program from the disk into memory, into the address space of the process.
  • OS allocates memory for run-time stack, e.g. local variables, function parameters.
  • OS allocates memory for program’s heap, e.g. dynamically-allocated data.
  • OS prepares I/O related setup, e.g. get ready for standard input, output, and error.

After steps above, the OS will start the program running at the entry point, and transfers control of the CPU to the newly-created process, and let the program begin its execution.

Processes States

  • Running:the process is running on a processor.
  • Ready: the process is ready to run but not run however.
  • Blocked: the process is blocked until some other event takes place, e.g. I/O will block the process.
https://docs.oracle.com/cd/E19683-01/816-5042/psched-16/index.html

Process data structures

The OS need some data structures to track information e.g. the state of each process. For example, a process list contains information about all processes in the system. Each process entity has a process control block (PCB).

That’s so much of it!

Happy Reading!

--

--

No responses yet