Processes and Threads Flashcards

1
Q

Processes

A
  • A process is an abstraction of a running program
  • It enables doing several things at the same time
  • support the ability to have (pseudo) concurrent operation
  • Ex. consider a user PC ??
  • In a multiprogramming system, the CPU switches from process to
    process quickly, running each for tens or hundreds of milliseconds
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Process and Program

A
  • A process is an activity of some
    kind
  • A program is something that
    may be stored on disk, not doing
    anything
  • Ex: baking vs. recipe
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The Process Model

A
  • All the runnable software on the computer, sometimes including the
    operating system, is organized into a number of sequential processes
  • To understand the system, it is much easier to think about a collection
    of processes running in (pseudo) parallel
  • This rapid switching back and forth is called multiprogramming
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The Process Model

A

a) Multiprogramming four programs.
b) Conceptual model of four independent, sequential processes.
c) Only one program is active at once

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

Process Creation

A
  • Events which cause processes creation:
    1. System initialization.
    2. Execution of a process creation system call by a running process.
    3. A user request to create a new process.
    4. Initiation of a batch job.
  • In all these cases, a new process is created by having an existing
    process execute a process creation system call.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Process Termination

A
  • Events which cause process termination:
    1. Normal exit (voluntary).
    2. Error exit (voluntary).
    3. Fatal error (involuntary).
    4. Killed by another process (involuntary).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Process States

A
  • Three states a process may be in:
    1. Running (actually using the CPU at that instant).
    2. Ready (runnable; temporarily stopped to let another process run).
    3. Blocked (unable to run until some external event happens)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Implementation of Processes

A
  • The lowest layer of a process-structured operating system handles
    interrupts and scheduling.
  • Above that layer are sequential processes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Process Table

A

One entry per process
* Contains important information
about the process’ state
* Information that must be saved
when the process is switched
from running to ready or blocked
state so that it can be restarted
later

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

Interrupt Handling and Scheduling

A
  1. Hardware stacks program counter, etc.
  2. Hardware loads new program counter from interrupt vector.
  3. Assembly language procedure saves registers.
  4. Assembly language procedure sets up new stack.
  5. C interrupt service runs (typically reads and buffers input).
  6. Scheduler decides which process is to run next.
  7. C procedure returns to the assembly code.
  8. Assembly language procedure starts up new current process.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Threads

A
  • In many applications, multiple activities are going on at once
  • Threads give the ability for the parallel entities to share an address
    space and all of its data
  • not possible with multiple processes (with their separate address spaces)
  • Threads are lighter weight than processes, so they are easier (i.e.,
    faster) to create and destroy
  • Threads allow computing and IO activities to overlap
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Thread Usage - A Word Processor

A
  • First thread interacts with the user.
  • Second thread handles reformatting in the background.
  • Third thread handles the disk backups.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Thread Usage - A Multithreaded Web Server

A

The dispatcher reads incoming requests for work from the
network and chooses an idle (i.e., blocked) worker thread to
hand the request

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

The Classical Thread Model

A
  • Multithreading is the situation of allowing multiple threads in the
    same process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Advantages of Thread over Process

A
  • Responsiveness:
  • If the process is divided into multiple threads, one thread can complete its
    execution and its output can be immediately returned.
  • Faster context switch:
  • Context switch time between threads is lower compared to process context
    switch. Process context switching needs more CPU overhead.
  • Effective utilization of multiprocessor system:
  • If we have multiple threads in a single process, then we can schedule multiple
    threads on multiple processor.
  • Resource sharing:
  • Resources like code, data, and files can be shared among all threads within a
    process. (Stack and registers can’t be shared)
  • Communication:
  • Communication between multiple threads is easier, as the threads shares
    common address space. while in process we have to follow some specific
    communication technique for communication between two process.
  • Enhanced throughput of the system:
  • If a process is divided into multiple threads, and each thread function is
    considered as one job, then the number of jobs completed per unit of time is
    increased, thus increasing the throughput of the system.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Inter-process Communication (IPC)

A

Processes frequently need to
communicate with other
processes:
* To pass information from process
to another
* To enable proper sequencing
when dependencies are present
* To ensure that no two processes
are ever in their critical regions at
the same time.

17
Q

Mechanisms for IPC:

A
  • Atomic read/write
  • Locks
  • Semaphores
  • Monitors
  • Message Passing
18
Q

Race Conditions

A
  • Two or more processes are
    reading or writing some shared
    data and the final result depends
    on who runs precisely when
  • Ex. two processes want to access
    the printer spooler directory at
    the same time
19
Q

Conditions Required to Avoid Race Condition

A
  1. No two processes may be simultaneously inside their critical regions.
    – Mutual Exclusion (mutex)
  2. No assumptions may be made about speeds or the number of CPUs.
    – No Assumption
  3. No process running outside its critical region may block other processes.
    – Progress
  4. No process should have to wait forever to enter its critical region.
    – No Starvation
20
Q

Critical region

A

the part of the program where shared variables are
accessed

21
Q

Mutual Exclusion with Busy Waiting

A
  • Disabling interrupts
  • Each process disables all interrupts just after entering its critical region and
    re-enable them just before leaving it
  • In a multicore (i.e., multiprocessor system) disabling the interrupts of one
    CPU does not prevent other CPUs from interfering with operations the first
    CPU is performing
  • Lock variables
  • A single, shared (lock) variable, process sets it to 1 and enters the critical
    region. If the lock is already 1, the process just waits until it becomes 0.
  • Has the same fatal flaw that we saw in the spooler directory.
  • Strict alternation
  • two processes strictly alternate in entering their critical regions
  • it is not really a serious candidate as a solution because it violates condition 3
  • Peterson’s solution
  • The TSL instruction