Lecture 3: Processes and threads Flashcards

1
Q

What is the execution sequence?

A
  1. Fetch instruction at PC and save it in IR (instruction register)
  2. Decode instruction in IR
  3. Execute (possibly using registers)
  4. Write results to registers or memory
  5. Update PC
  6. Repeat
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does this mean:

lw r1, 100

A

Load the word from 100 into register r1.

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

What does this mean:

add r3, r1, r2

A

add r1 + r2 and save it in r3

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

What does this mean:

sw r3, 100

A

store the word that’s in r3 into address 100

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

What is a context (of execution)?

A
  1. The value of the registers (PC, stack pointer, heap pointer, etc.) - from the CPU
  2. What’s written in the memory (code, data, stack, heap)
  3. Internal data in the OS relevant to the program (user, priority, etc.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When does the context change?

A

Every time there’s a change in the value of a register or the memory.

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

What is a process?

A

A process is a dynamic instance of an application execution
(an abstraction of “an individual computer”).

Moving between contexts is the process.

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

Resident process

A

A process that is currently executing on a CPU

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

Non-resident processes

A

Process that is not currently running in the CPU. The context is stored in a special location in memory.

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

When does a program become a process?

A

when the executable file is loaded into the memory (by the loader which is a component of the OS)

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

Every time you run a program it creates a new ____.

A

Every time you run a program it creates a new process.

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

A program can create ____ processes.

A

A program can create multiple processes.

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

Address space

A

The set of accessible addresses in the memory by the process (Given by two parameters: base and bound)

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

Who verifies that a process is accessing memory only in [base, base+bound]?

A

The CPU

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

When a process specifics address x, what does it actually mean?

A

base + x

This means that the same pointer address in different processes point to different memory.

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

Kernel memory

A

The OS’s address space

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

User memory

A

All the memory that isn’t the kernel’s memory (The OS’s address space)

18
Q

When switching between processes, what needs to be saved?

A

The processes context (including everything in the CPU)

Everything in the memory does NOT need to be copied. (because no other process will be able to access it, because it is outside of the process’s address space)

19
Q

PCB

A

Process control block:

A data structure that saves all the data the OS needs about a process.

20
Q

What information is saved in a PCB?

A
  1. Process state (resident, reday, etc. and info for calculating the process’s priority)
  2. Process number
  3. Registers (including PC)
  4. Memory limits - base and bound
  5. List of open files
21
Q

What are the states of the process? (Life-cycle)

A
  1. New - being created
  2. Running - being executed
  3. Waiting (=blocked) for some event (disk, terminal, timer)
  4. Preemption - going from running directly back to ready (without first waiting)
  5. Terminated
22
Q

What is preemption and when does it occur?

A

Preemption is when a process is running and then gets kicked off but goes directly to the ready queue (no waiting).
Can only happen in time sharing and not multiprogramming.

23
Q

What causes a process from being in a running state to a ready state?

A

An interrupt (for example sys call)

24
Q

What causes a process from being in a ready state to a running state?

A

Scheduler dispatch

25
Q

What causes a process from being in a running state to a waiting state?

A

I/O or event wait

26
Q

What causes a process from being in a waiting state to a ready state?

A

I/O or event completion

27
Q

CPU Scheduler

A

CPU Scheduler: Decide which process should run on the CPU (and sometimes for how long)
(“Short-term scheduling”; tens/hundreds times a second)

28
Q

Dispatcher

A

Dispatcher: The module responsible for executing the CPU scheduler decisions (context switch, switching back to user mode)

29
Q

Schedule vs dispatcher

A

Scheduler - המוח
Dispatcher - הכוח

Scheduler decides who should run and for how long. The dispatch is the one who copies the registers to the PCB, and the PCB to the CPU, and changes the mode from user to kernel, (or kernel to user) etc.

30
Q

How does the OS save the PCBs?

A

As linked lists. There is a linked list for the processes that are in the ready state, terminated state, waiting, etc.

31
Q

When can the PCB be updated?

A

Only during the context switch when the OS is the resident program in the CPU.
During the running of the program, the OS isn’t running , so the PCB can’t be updated. Only in kernel mode can the data structure of processes be accessed, so we need to wait for the resident program to be the OS.

32
Q

What are the steps in a context switch between processes?

A
  1. Save processor context, including program counter and other registers
  2. Update the PCB with the new state and any accounting information
  3. Move PCB to appropriate queue - ready, blocked/waiting
  4. Select another process for execution
  5. Update the PCB of the process selected
  6. Update memory-management data structures
  7. Restore context of selected process
33
Q

When are processes switched?

A
  1. Interrupts (from the clock or from I/O)
  2. Memory fault
  3. System call (program purposely gives up the CPU)
  4. Exception (error occurred)
34
Q

What is the purpose of the clock’s interrupt?

A

To pass the control back to the OS.

35
Q

When are processes created?

A
  1. Initializing system
  2. fork() - a process creates another process
  3. User request (e.g., double click on icon, typing a command)
  4. initiating batch job.
36
Q

What type of function is “fork()”?

A

A system call

37
Q

What does the function “fork()” do?

A

Creates a new process with an identical PCB (except for process ID), allocate memory for the new process and update bounds. The child process returns a 0 and the parent returns the child’s ID (nonzero)

38
Q

pid

A

Process ID

39
Q

When a process is running and there’s a sys call, what state does the process transfer to?

A

Ready

40
Q

Why does the CPU do the calculation of variable+base?

A

This way if a process is forked, there will be two areas of memory, so the stack pointer will be in relation to the base of the current process.

41
Q

When the fork() functions finishes running, which process will run (the parent or son)?

A

Depends! The scheduler will decide.

42
Q

Why is it important for the parent process to have the son’s ID?

A

Often time the parent process overseas\controls the son processes, and therefore it needs to know their IDs.