System calls, Processes and Threads Flashcards
What are the two processer modes?
Kernel mode and User mode
What mode do system calls operate in?
Kernel mode
What is meant by System Calls?
- OS is trusted, user is not
- OS has super-privileges, user does not
- Must take measures to prevent abuse
What is meant by Function Call?
Caller and callee are in the same process, same user, same domain of trust
What are some examples of POSIX system calls?
- fd: open a file for reading, writing or both
- s: close an open file
- n: read data from a file into a buffer
What is meant by a process?
A program in execution, which then forms the basis of all computation (an active entity)
What is meant by a Process Control Block (PCB)?
Keeps all the information needed to keep track of a process, maintained by the OS for every process
What are the 3 main memory segments for a process?
- Text: executable code for the process
- Data: statically defined variables
- Stack: return address for procedure calls
What is meant by Multiprogramming?
- Individual processes oblivious to existence of others
- Processor rapidly switched between processes
- Processes suspended and restarted
- Context switch can be expensive
What is the Process Model?
- Multiprogramming of 4 programs
- Conceptual model of 4 independent, sequential processes
- Only one program active at any instant
What are the 4 principal events that cause processes to be created?
- System initialisation
- Process creation system call
- A user request to create a new process
- Initiation of a batch job
What is meant by Fork() in POSIX system calls?
Fork creates a new process by cloning the parent process
How do Parent/Child run in parallel?
- By running on different processors if on a multiprocessor system, otherwise by context switching
What is meant by Context Switching?
Running each process in short time slots
- Saving context of one process, restoring that of another one
- Processor alternates between executing different processes
What are 3 states a process may be in?
- Running (using the CPU at that instance)
- Ready (paused to let another process run)
- Blocked (waiting for some external event to happen)
What is meant by a Process Table?
- Records information required to restart a suspended process
- Timer sends periodic interrupts
- Schedular saves state of process before starting another
What are some advantages of processes?
- Program can be written as if it had the computer itself
- Memory protection
- Multiprogramming achieved by the OS
What are some disadvantages of processes?
Context switches are very expensive
What are some alternatives to processes?
Threads, much cheaper to switch threads than processes
What is a thread?
A basic unit of CPU utilisation, consisting of a program counter, a stack and a set of registers (and a thread ID)
What is meant by the Classical Thread Model?
Each thread has its own stack, each thread will generally call different procedures and thus have a different execution history
What are some advantages of threads?
- Less memory to maintain thread state (mostly extra stack space)
- Less performance overhead
- Automatic data sharing (same address space)
What are some disadvantages of threads?
- Shared memory can be source of data races
- Less robust compared to processes
- Memory corruption or a crash on 1 thread corrupts entire program
Process vs Thread
- Process means a program is in execution, thread means a segment of a process
- Process is not lightweight, a thread is
- Process consume more resources, threads consume fewer
- Process memory is mostly isolated, threads share memory
- Process does not share data, threads share data with each other
What is meant by a Race Condition?
- 2 or more processes are reading or writing some shared data
- Precise outcome depends on the exact scheduling and timing of processes
What is meant by Mutual Exclusion?
Only one process can access a shared resource (e.g. memory) at the same time
What is meant by Critical Region?
The part of program potentially causing a race condition
What is Serially Re-usable resource (SRR)?
A resource that required mutual exclusion
What is a critical region for Mutual exclusion?
No 2 processes may be simultaneously inside their critical regions
What is a critical region for Architectural Neutrality?
No assumptions may be made about speeds or the number of CPUs
What is a critical region for Progress?
No process running outside its critical region may block other processes
What is a critical region for Bounded Waiting?
No process should have to wait forever to enter its critical region