Program
Executable code, or source code
- Static
Process
is a running program
- Active
- Can be started by a GUI, command line or by another process
2 types of processes
Foreground process - interacts with user
Background process - runs to completion and report results (to file or window)
Process consists of
Process ID
When a process runs, Linux keeps track of it
through a process ID (PID)
* When linux boots, the first process created is an initialization process call systemd (or init )
* Systemd is given PID = 1
* Each new process gets next available PID
* If your computer hasn’t been rebooted in a while, the PIDs could be in tens of thousands
* Each process also has a Parent PID
* PID of the process which created it
Process creation
Process can only be created by another process
* Parent Process creates (spawns) one or more child processes
System calls are used to create process
a system call is function call to Linux Kernel
Process creation
Process can only be created by another process
* Parent Process creates (spawns) one or more child processes
* System Call = Function call to Linux Kernel
* To create a process, System call is required
* fork()
* exec()
* wait()
* vfork
Process consists of
Region of memory which includes executable instructions and process specific data
Fork
Duplicates Parent process to create child
Creates new region of memory, and duplicates contents of memory
* E.g Process A creates process B
Wait
Duplicates parent process to create child
Parent sleeps until child terminates
Exec
Exec system call causes a process to start a new program which replaces the current process.
In other words, creates a new process which replaces the current process
vfork
operates in the same way as fork, with one exception
The parent and the child share the same memory
fork + exec
Typical usage of exec is to pair it with fork
1. Parent calls fork to create a new process with a new PID
* New process is a duplicate of the parent
What is a computer? CPU
The CPU consists of
Control Unit
* Handles the fetch
execute cycle
* Controls the other components of the computer through signals
* Contains registers (storage locations) for important pieces of
information like the memory location of the next instruction in the
program and the current instruction
What is a computer? CPU
Consider an example:
* We write the instruction A = B * (C + D)
* This is broken into several lesser machine code instructions
* Load C into a data register
* Add D to the data register storing C
* Multiply B to the data register storing C + D
* Store result in A
Explain what happens as process executes
The state of the process changes
* Variables change values
* Portions of program move from swap space to memory
* CPU Registers Change
* Current instruction changes (IP)
* Instruction that the processor will execute next changes (PC)
* Status flags change
As a process executes, state of the process changes
Process Management
Process management has evolved over the years from single process execution to concurrent processing.
Single Process Execution
Single Tasking
* OS starts a process
* CPU operates on just this process
* Computer thus only run one process at a time
* Process must terminate (or suspended by user) before another
process can be executed.
Single Process Execution
BATCH
Batch does not get efficient use from CPU
* E.g. process is running, and needs to read from disk
* Process must wait for slow disk to return data
* When process is waiting, CPU is sitting idle
Concurrent Processing
Multi programming
* When a process is performing time
consuming I/O,
process is removed from CPU and replaced with a
different process.
* Looks as if more that one process is executing at the same time
* Replacement of Process is called
Context Switch
Context switch
Multi-tasking