|
|
+++
|
|
|
title = "Processes"
|
|
|
+++
|
|
|
|
|
|
# Processes
|
|
|
|
|
|
Who needs process isolation? - Intel Marketing on Meltdown and Spectre
|
|
|
|
|
|
To understand what a process is, you need to understand what an operating system is. An operating system is a program that provides an interface between hardware and user software as well as providing a set of tools that the software can use. The operating system manages hardware and gives user programs a uniform way of interacting with hardware as long as the operating system can be installed on that hardware. Although this idea sounds like it is the end-all, we know that there are many different operating systems with their own quirks and standards. As a solution to that, there is another layer of abstraction: POSIX or portable operating systems interface. This is a standard (or many standards now) that an operating system must implement to be POSIX compatible – most systems that we’ll be studying are almost POSIX compatible due more to political reasons.
|
|
|
|
|
|
Before we talk about POSIX systems, we should understand what the idea of a kernel is generally. In an operating system (OS), there are two spaces: kernel space and user space. Kernel space is a power operating mode that allows the system to interact with the hardware and has the potential to destroy your machine. User space is where most applications run because they don’t need this level of power for every operation. When a user space program needs additional power, it interacts with the hardware through a system call that is conducted by the kernel. This adds a layer of security so that normal user programs can’t destroy your entire operating system. For the purposes of our class, we’ll talk about single machine multiple user operating systems. This is where there is a central clock on a standard laptop or desktop. Other OSes relax the central clock requirement (distributed) or the “standardness” of the hardware (embedded systems). Other invariants make sure events happen at particular times too.
|
|
|
|
|
|
The operating system is made up of many different pieces. There may be a program running to handle incoming USB connections, another one to stay connected to the network, etc. The most important one is the kernel – although it might be a set of processes – which is the heart of the operating system. The kernel has many important tasks. The first of which is booting.
|
|
|
|
|
|
1. The computer hardware executes code from read-only memory, called firmware.
|
|
|
|
|
|
2. The firmware executes a bootloader, which often conforms to the Extensible Firmware Interface (EFI), which is an interface between the system firmware and the operating system.
|
|
|
|
|
|
3. The bootloader’s boot manager loads the operating system kernels, based on the boot settings.
|
|
|
|
|
|
4. Your kernel executes `init` to https://en.wikipedia.org/wiki/Bootstrapping itself from nothing.
|
|
|
|
|
|
5. The kernel executes startup scripts like starting networking and USB handling.
|
|
|
|
|
|
6. The kernel executes userland scripts like starting a desktop, and you get to use your computer!
|
|
|
|
|
|
When a program is executing in user space, the kernel provides some important services to programs in User space.
|
|
|
|
|
|
- Scheduling processes and threads
|
|
|
|
|
|
- Handling synchronization primitives (futexes, mutexes, semaphores, etc.)
|
|
|
|
|
|
- Providing system calls such as `write` or `read`
|
|
|
|
|
|
- Managing virtual memory and low-level binary devices such as USB drivers
|
|
|
|
|
|
- Managing filesystems
|
|
|
|
|
|
- Handling communication over networks
|
|
|
|
|
|
- Handling communication between processes
|
|
|
|
|
|
- Dynamically linking libraries
|
|
|
|
|
|
- The list goes on and on.
|
|
|
|
|
|
The kernel creates the first process `init.d` (an alternative is system.d). init.d boots up programs such as graphical user interfaces, terminals, etc – by default, this is the only process explicitly created by the system. All other processes are instantiated by using the system calls `fork` and `exec` from that single process. |