Week 11 - Linux Processes Flashcards
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
- Set of executable instructions
- Region of memory which stores:
- Executable instructions
- Process specific data (values in variables)
- Call Stack
- Operating System resources
- File descriptors
- Security attributes
- Process owner & permissions
- Processor State
- Content of CPU registers
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
- Wait system call is same as fork with one key difference
- The parent goes into a wait state (sleep) until the child terminates
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
- The child then calls exec to change the process to execute a different program
What is a computer? CPU
- The processor (central processing unit, CPU)
- Performs the fetch
execute cycle
- Fetch next program instruction from memory
- Decode the instruction into actions
- Command the relevant part(s) of the computer to operate to
execute the instruction - Store the result somewhere (if necessary)
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
- Arithmetic Logic Unit (ALU)
- Digital circuits to perform arithmetic and logic operations
- Data registers to store data being used by the current set of
instructions