Slides 6 Flashcards
Define Multiprogramming
OS gives CPU to another program if current program must wait on I/O
Define cooperative multitasking
programs can voluntarily yield CPU to another program
Define preemptive multitasking
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
Difference between program and process
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
What does a process look like in memory?
• 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)
What are some parts of the process control block? (PCB)
• 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.
What are some fields in PCB?
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
What does fork return?
If it fails, -1
Otherwise returns process ID number (If child PID == 0)
how do we start an external program in Unix programmatically?
replace child process with an external program using exec()
What does popen() do?
The popen() function opens a process by creating a pipe, forking, and invoking the shell
How do process trees work in windows vs Unix?
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
What is the first process started after booting and why is it important?
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
What 2 special processes aren’t descendants of init?
swapper and pagedaemon
What is CPU utilization and how is it calculated?
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
What 4 reasons can a process create new processes?
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