Processes and Threads Flashcards

1
Q

Motivation for Processes

A

Modern computer systems perform many tasks seemingly at the same time

  • wait for user input
  • network communication
  • waiting for I/O requests to finish
  • background computation

A process is an OS concept to seperate this complexity into units that are each executed sequentially

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Program vs. Process

A

Programs are sets of instructions and data that describe how to execute a certain task

Processes are instances of running programs

  • they have a current state associated with the “core image”
  • state includes the processor registers and resources a process uses (e.g. opened file handles)

There may be multiple instances of the same program at the same time
-> multiple processes can execute the same program, but with different input data, at a different stage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The process model

A
  • with only a single CPU core, only one process can be executed at a time
  • multiple processes are executed in turn
  • one local program counter for every process
  • one global program counter (CPU)
  • -> switched between local values when switching processes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Process Lifetime

A

Processes are created at/by:

  • system initialization (bootup)
  • in response to another process requsting its creation by the respective system call
  • a user request to create the process
  • batch job

Background processes are called services or daemons .

Processes are terminated by:

  • normal exit
  • error exit
  • fatal error
  • killed by another process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Process States

A

Running: using the CPU at this instance
Ready: runnable but temporarily stopped in favor of a running process
Blocked: waiting for external event (e.g. I/O interrupt)

(see Slide 9)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Processes = A Program in Execution (Definition)

A

A process holds all information required to run that program

  • unique identifier for the process
  • pointers to adress regions
  • handles to additional resources
  • current state of execution
  • priority for scheduling

On UNIX systems:

  • information about child processes
  • child processes can be controlled by parents
  • one root process for the whole OS to bootstrap startup of and control other processes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Context Switching

A

Switching from one process to another:

  1. setting the currently running process to blocked or ready
  2. saving its current state in process table
  3. selecting another ready process according to scheduling decision
  4. restoring the process context
  5. setting new process to running
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Threads Motivation

A
Processes have their own address space.
There may be multiple processes running the same program, but they do not share any internal state.
In many cases, having multipe parallel tasks share one address space makes programming simpler:
- reading data from keyboard
- text formatting
- saving data to disk
- spelling checker 
- prepare printing 

All running at the same time and not blocking each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Threads

A

Like processes, have their own execution state

  • running, ready or blocked
  • scheduling priority
  • CPU registers

Similar motivation as processes:

  • simpler programming model with sequential tasks
  • higher CPU utilization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Classical thread model

A

Difference ro process is shared resources

  • includes RAM, network sockets, file handles,…
  • threads are sometimes called light-weight processes, because shared resources can lead to faster thread creation and thread switching

1 program has 0…n processes
1 process has shared resources + 1…m threads

Process is the owner of resorces and a kind of container for its threads. Threads use the resources of their process on a shared basis.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Process vs. Thread information

A

Per process items:

  • Adress space
  • global variables
  • open files
  • child processes

Per thread items:

  • program counter
  • register
  • stack
  • state
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Threads execution stacks

A

Threads in a process share text and data areas

Each thread has its own stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

User Space Threads (FIBER)

A
  • have thread tables in user space so the kernel does not need to switch contexts
  • this makes fiber fast
  • however the integration with system calls is difficult
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

IPC = Inter Process Communication Issues

A

3 basic issues for inter process communication

  • passing information from one process to another
  • ensuring that two or more processes do not conflict
  • dependencies between processes (e.g. producer/consumer)

Same principles apply to threads:

  • passing information is trivial because of shared memory
  • conflict handling and sequencing apply equally to threads
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Options for IPC medium

A

Files: in a shared file system (typical for processes to access the same file system )
Named Pipes: pseudo files without permanent storage but FIFO queue in kernel
Anonymous pipes: e.g. shell connecting stdout of one process to stdin of another
Client/server communication over sockets: server sockets listen for incoming connections, cklient sockets connect to them to form 1:1 link
shared memory regions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Race condition und Critical Regions

A

sequentielle Ausführung von instructions verschiedener Threads darf nicht so verschachtelt werden, dass die Reiehenfolge der Ausführung einen Einfluss auf das Ergebnis hat.
Daher kann man critical regions definieren, die nicht unterbrpochen werden können. Z.b. lesen, ändern und schreiben einer einheit muss als atomare Einheit erfolgen.

17
Q

Scheduling

A
  • describes the process of assigning resources to tasks at appropriate times for their execution
  • applies to all resources shared by multiple tasks
    • CPU time
    • mass storage access operations
    • network packets
    • other IO device access
  • part of the OS that performs schduling is also called scheduler
18
Q

Short Term Scheduling: Non preemptive

A

Can classify OS is terms of short-term scheduling:
Non Preemptive: running tasks processes threads cannot be interrupted by other tasks until they exit, block or yield control to the scheduler
exception: interrupts are still processes
- multiprogramming only possible with cooperative multitasking

19
Q

Short term scheduling preemtive:

A

running tasks can be suspended in favor of other “more important” tasks; allows preemptive multitasking to be implemented without the implicit cooperation of processes

20
Q

Short term scheduler Execution

A
  • Short term scheduler needs to become active when:
  • last running process ended (or blocked, yielded) or another ready process has higher priority

Then decide which of the processes (threads) in ready queue should be selected to run
- in none is ready to be executed, then schedule (dummy) IDLE process, or go to sleep, reduce CPU frequency

For non-preemptive OS: only on exit/block
For cooperative multitasking OS: additionally possible for a process/thread to yield

For preemptive OS: additionally possible for sheduler to set process from running to ready

21
Q

Scheduling algorithms

A

Batch Systems (typcically non-preemptive)

  • first come first served
  • shortest job first and shortest remaining time next
  • priority queuing (optionally with aging)

Interactive systems:

  • Round-Robin (RR)
  • priority queuing
  • others: multiple queues, shortest process next, guaranteed, lottery, fair-share

Realtime systems: