Process Flashcards
What is an OS’s task?
1) Abstraction: hide hardware details from applications/programmers/users
2) Resource Management: resources must be multiplexed in a fair way between applications/users
3) Protection: Different applications shouldn’t be able to disturb/manipulate each other
4) PROVIDING AN EXECUTION ENVIRONMENT FOR APPLICATIONS
Why is abstraction a central task of an OS
- to hide implementation details of the hardware from the applications
- make it easier to develop applications
- increase application compatibility
- improve reliability by taking away complexity
Why is protection still as important although most devices run an OS used by a single user only?
- protective measures such as the separation into user and kernel modes increases the reliability of the system
- a buggy application might crash the whole system, leading to data loss
- to protect user’s data from untrusted sources in today’s interconnectivity of the computers
What is the advantage of fixed-size integer types like uint32_t?
The normal int types have different sizes depending on the OS. The fixed-size types help writing portable code; code that works on multiple different systems without modification
Explain all functions of * and & operators
- *: in front of a variable name declares that variable to be a pointer: *pointer1
- *: in front of a pointer variable dereferences the pointer: return *pointer1
-&: in front of a variable returns the address of that variable, which is a pointer: pointer2 = ¬apointer
User mode
-only non-privileged processor instructions can be executed
kernel mode
- allow the execution of all instructions
- some activities that control & manage the system as a whole may only be performed in kernel mode
- it is needed to avoid other applications to use the system according to their own needs while negatively affecting other applications; by occupying the system resources as long as they need
What are privileged instructions and give examples
Instructions that
- manipulate control registers for memory translation
- disable or enable interrupts
- access platform devices
+Load and store control registers
+Halt processor
+Write model-specific registers
+Read time-stamp counter
Basic data types in C
-char: 1B
-short: 2B
-int: 4B
-long long: 8B
-float: 4B
-double: 8B
Global variables
- live while the program runs
- placed in the data segment
Local variables
- accessible and valid only in the scope of the block/function in which they are declared
- placed on the stack or in CPU registers
What is a process?
A process is a program in execution - an instance of a program
Each process is associated with a OS data structure called process control block (PCB) that holds all state information
Concurrency vs parallelism
Concurrency: Multiple processes on the same CPU
Parallelism: Processes truly running at the same time with multiple CPUs
What is direct execution and its problems?
Direct execution: Allow user process to run directly on hardware, OS creates process and transfers control to starting point
Problems:
- Process can harm each other
- Could read/write other process data
- Process could run forever
- Process could do something small
80:20 rule
Programs can see more memory than available:
80% of process memory idle, 20% active working set
What are three kinds of data
- Fixed size data items
- Data that is naturally free’d in reverse order of allocation
- Data that is allocated and free’d dynamically at random
Fixed-size data and code segments
- BSS: variables that haven’t been initialized, the executable file typically contains the starting address and size of BSS, the entire segment is initially zero
- Data segment: initialized data elements
- Read-only data segment: constant numbers and segments
Typical process address space layout
OS: Addresses where the kernel is mapped
Stack: Local Variables, function call parameters, return addresses
->
<-
Heap: Dynamically allocated data (malloc)
BSS: uninitialized data
Data: initialized data
RO-Data: Read-only data, strings
Text: Program, machine code
Processes vs threads
thread -> lightweight process
an execution stream that shares an address space
multiple threads within a single process
(multiple stacks within the same address space)
What are three occasions that invoke the kernel and switch to kernel mode?
-Syscalls: user mode process requires higher privileges
- interrupts: external device sends a signal to the CPU
- exceptions: CPU realizes a notable condition
types of syscalls
- process control
- memory management
- file management
- device management
- communication
- information maintenance
- system management
Trap instruction
The trap instruction switches the CPU to kernel mode and enters the kernel in the same predefined way for every syscall.
It is a procedure call that synchronously transfers the control
System Call Handler
- Saves registers
- Reads parameters that were passed by the caller
- Checks parameters
- Checks if the process has permission to perform the requested action
- Performs the requested service on behalf of the process
- Returns to the caller with a success or error code
What are possible events that cause processes to be created?
- System initialization
- Process creation syscall issued by a running process
- User request to create a new process
- Initiation of a batch job