Slides 6 Flashcards

1
Q

Define Multiprogramming

A

OS gives CPU to another program if current program must wait on I/O

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

Define cooperative multitasking

A

programs can voluntarily yield CPU to another program

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

Define preemptive multitasking

A

a program gets a fraction of a second to execute, then OS automatically switches to the next program, and so on
■ almost all modern OSes implement this

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

Difference between program and process

A

a program is a passive entity
• an executable file containing a list of instructions, usually stored on disk

a process is an active entity
• associated with a program counter and other resources

a program becomes a process when it is loaded into memory for execution

a single program can be used to create multiple processes • eg. running multiple instances of one executable

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

What does a process look like in memory?

A

• text section: the program code
• data section: global variables, constant
variables
• heap: memory for dynamic allocation during runtime
• stack: temporary data (parameters, return address, local variables)

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

What are some parts of the process control block? (PCB)

A

• process state
• program counter, CPU registers
• priority, pointers to various queues
• memory management info: eg. page tables, segment
tables, etc.
• accounting info: eg. CPU time, timeout values, process
numbers, etc.
• I/O status info: open files, I/O devices, etc.

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

What are some fields in PCB?

A
process state
priority
scheduling parameters process ID
parent process
pointer to text segment 
pointer to data segment 
pointer to stack segment
root directory 
working directory
file descriptors 
user ID
group ID
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does fork return?

A

If it fails, -1

Otherwise returns process ID number (If child PID == 0)

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

how do we start an external program in Unix programmatically?

A

replace child process with an external program using exec()

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

What does popen() do?

A

The popen() function opens a process by creating a pipe, forking, and invoking the shell

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

How do process trees work in windows vs Unix?

A

in Unix, parent and child processes continue to be associated, forming a process hierarchy

in Windows, all processes are equal, the parent process can give the control of its children to any other process

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

What is the first process started after booting and why is it important?

A

init or systemd is the first process started after booting
• older UNIX systems used init based systems
• many popular Linux systems now switched to systemd

init is the ancestor of all user processes (direct or indirect parent) i.e root of process tree

init always has PID = 1

orphaned process(processes whose parents have terminated for whatever reason) are adopted by init

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

What 2 special processes aren’t descendants of init?

A

swapper and pagedaemon

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

What is CPU utilization and how is it calculated?

A

probability that at least one of the processes is not waiting on I/O

1 - (probability that all processes are waiting on I/O)
for all processes, you multiply the probably of each process waiting together

or under simplistic multiprogramming model
CPU utilization = 1 - p^n
where p is a fraction of the time the process spends waiting on I/O
where n is the number of similar processes

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

What 4 reasons can a process create new processes?

A

system initialization (boot)
• background processes ― daemons, services
• application decides to spawn additional processes • eg. to execute external programs or to do parallel work
• a user requests to create a new process • eg. launching an application from desktop
• starting a batch job • mainframes

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

Each process gets its own ____ created during process creation

A

Address Space

17
Q

What are some options for allocating resources to a new process?

A
  1. child obtains resources directly from the OS • most common, easiest to implement
  2. child obtains subset of parent’s resources
    • eg. parent decides to give up some if its resources so that a child can use them
  3. parent shares some/all resources with the child
  4. hybrids
18
Q

What does a parent do when a child process is created?

A
  1. Waits till it dies
  2. continues independently and at same time
  3. works in sync with child
19
Q

What are the types of process termination?

A

voluntary (exits with exit() or exitProcess())
- normal exit (app is done or user done with app)
- error exit (application detects error)
Involuntary
-fatal error (bug in program i.e divide by zero)
external (killed by another process)

20
Q

What happens when a process is terminated in Unix?

A

the child processes may be terminated, or assigned to the grandparent process, or to the init process (hierarchy always maintained)

21
Q

What is the default behaviour of process termination in Linux?

A

default behavior on Linux is to reparent the child process to the init process

22
Q

When terminating a process what are some things that happen to resources owned by the processs?

A
  • OS must free all related resources, eg.
  • free memory used by the process
  • delete PCB
  • delete process from process table
  • kill children or assign them a new parent • close files
  • close network connections
23
Q

What is process scheduling?

A

part of multitasking is deciding which process gets the CPU next
• typical objective is to maximize CPU utilization

24
Q

What is a process scheduler?

A

kernel routine/algorithm that selects an available process to execute on
the CPU
• selected from processes in a ready queue

25
Q

What are the 4 Queues the OS maintains?

A
  • job queue: all programs waiting to run, usually found in batch systems • eg.priorityqueue
  • ready queue: all processes that are ready to execute their next instruction
  • eg. linked list, implemented via a pointers in PCBs
  • device queues: processes waiting for a particular device • each device has its own queue
26
Q

What are the 3 process states

A

■ running ― actually running on the CPU
■ blocked ― wait􏰀ng for some event to occur, eg. I/O
■ ready ― the process is ready to execute on CPU

27
Q

What is context switching?

A

OS switches between contexts(states) to go from one process to another

28
Q

What happens during context switching?

A

when OS switches between processes A and B:
• OS first saves A’s state in A’s PCB
• eg.save current CPU registers into PCBA
• OS then restores B’s state from B’s PCB
• eg.load CPU registers from PCBB

29
Q

Where does context switching occur and why?

A

context switch occurs in kernel mode:
• for example when process exceeds its time slice
• enforcing time slice policy usually implemented via timer interrupt
• or when current process voluntarily relinquishes (yields) CPU, eg. by sleeping
• or when current process requests a blocking I/O operation, or any blocking system call
• or due to other events, such as keyboard, mouse, network interrupts

30
Q

What do signals do?

A

signals are used to notify a process that a particular event has occurred
• one process (or thread) sends a signal, another process (or thread) receives it
• it is possible for a process to signal itself

31
Q

What are the stages in the signal lifetime?

A

a signal is generated/sent, usually as a consequence of some event
• signal is delivered/pending to a process
• delivered signal is handled by the process via signal handler
• some signals can be ignored - signal delivered to a process that ignores
it is lost
• some signals can be blocked - signal stays pending until it is unblocked

32
Q

What is a signal handler and what kinds of signal handlers are there?

A

signal handler - a function that will be invoked when a signal is delivered
• default signal handler - all programs have default handlers with default behaviours
• a user-defined signal handler - programs can override the default handlers
• signals handled by a user-defined handler are ‘caught signals’

33
Q

When can signals be delivered?

A

signals can be delivered anytime, even while your program is in the middle of a function, or in the middle of applying an operator (C++)
• the state of your data might be in an inconsistent state • also signal handler could itself be interrupted

34
Q

What is a reentrant function?

A

reentrant functions are functions:
• that can be interrupted in the middle of an operation
• and then called again (re-entered)
• and finally the original function call can finish executing