Processes and threads Flashcards
How are threads and processes created?
Via system calls
What do Processes and Threads cause a need for in a system?
Virtual memory and protection
How does the OS deal with processes and threads?
OS schedules and concurrently executes them. kernel manages processes.
What is a process?
A unit of work being executed on a computer
Program in execution
What functions does the OS have for processes?
- Creation and deletion of processes
- Scheduling processes on the CPU
- Communication between processes
- Synchronisation of >= 2 processes.
Process structure
- Stack
- Heap
- Data
- Text
What is a process control block?
OS representation of a process, held in a table or list. Allows OS to suspend and continue processes.
What does the scheduler include that allows for the extraction on information on a process?
struct task_struct
pid, state, open files contained.
What is context and how do we switch it?
Process state.
Save state of old process, load state of new process.
What are the disadvantages of context switching?
Pure overhead as no useful work can be done while switch is in progress.
How are processes created?
Create process system call (fork()). Calling process is parent and new processes are children.
How does the parent/child process affect child nodes
Program: Same as parent or different
Resource sharing: Shared, partially shared or not shared.
Execution: Concurrently or waiting to finish
Address space: Copy of parent’s or completely new.
How are processes terminated?
Exit system call by process itself or parent can kill child process.
What is cascading termination?
When parent process terminates, so to do all children.
What is an orphan process?
On parent crash, process is adopted by the init process or terminated.
What is a Daemon?
Services, intentionally orphaned. Run background tasks.
What is a zombie process?
Process finished but parent hasn’t read return code.
What does fork do?
Create child with copy of parent’s address space, resources of parent also available to child.
What happens when fork returns?
Returns twice, parents get pid of child and child gets 0
How do we change the program run by a child process?
exec(pid, new_program, [parameters], NULL).
What happens in the process when exec occurs?
PID is retained, as are open file descriptors.
Overwritten: text, stack, heap and data
How is sharing memory between processes possible?
shm_open(“name”, oflag)
Map it into process space using mmap()
What are the characteristics of a thread?
Little private state:
Program counter, register set, stack
The rest is shared with other threads.
Why use threads and not processes?
A process can have separate threads for control of different parts.
Saves overhead of process creation and context switching
Easy inter-thread communication
Utilises multi-processor architectures