Quiz #4 Flashcards
How many program can execute at a time without a O/S?
Without an O/S, only one program can be executed at a time
How do you change the running program
A CPU reset and some way of loading a new program (flashing, loading from tape, etc.) is required to change the running program,.
How much control does the running program have?
The running program has full control and 100% use of the resources of the computer(since It is the only thing running)
How many programs can be ran with a O/S?
O/Ses allow more than one program to be loaded at a time and allow us the ability to switch between loaded programs using the concept of a process
What is a process? What can you do with them
a process is a program in execution. A process can be paused, restarted, stored and executed
What are the parts of a process?
- Processor registers including the program counter
- The program code, also called text section
- Stack containing temporary data; Function parameters, return addresses, local
variables - Data section containing global variables
- Heap containing memory dynamically
allocated during run time
What is a process’s address space? What are segments?
- A process’s address space is the range of memory addresses accessible by that process.
The address space is comprised of 3
segments and the heap. The text
segment, contains the executable code
(called the program text, but it is NOT
text!). the data segment contains
constant and global data. The stack
segment contains local variables.
Highest Memory Address
Stack
Heap
Data
Text
A program is a ____ entity stored on disk ( ____ ___), a process is ___
Programs become ___ when executed
every process must have ____ ____ ____
Several process may have the ___ ___
passive, executable file, active
process
exactly one program
same program
What is a process
A process is an activity of some kind. It
has a program, an address space input, output
and a register state.
What is a program?
A program is a set of executable instructions
that may be stored on disk, not necessarily
doing anything
If a program is running ___, it counts as ___ processes. The fact that ___ processes are running the same program doesn’t matter. They are ___ ____ processes.
twice, 2, two, 2 distinct
Which is a program and a process? A movie on a dvd, playing the movie
program - a movie on a dvd
process - playing the movie
Two users are logged into a single-CPU Linux server. User #1 begins a lengthy process to calculate pi to 50 decimal places: 3.14159265358979323846…. User #2 begins a equally lengthy process to sort 1000 names. Both users claim that the CPU is working on her problem. How can this be? There is only 1 CPU.
O/Ses allow more than one program to be loaded at a time and allow us the ability to switch between loaded programs using the concept of a process.
- CPU switches from process to process quickly, giving the illusion of ____
- Each process is allowed to run for tens or hundreds of millisecond stretches (called a ____ ____ or ____ )
- This rapid switching is called _____
parallelism
time slice, quantum
multiprogramming
How does the CPU do multiprogramming?
- multiprogramming through rapid
context switching between processes amounts to the O/S abstracting a single physical CPU into multiple virtual CPUs (one per process). - From each process’s point of view, it is running
on a dedicated CPU.
What is the core component of the operating system kernel? What is above that layer?
process scheduler
the set of processes to be sequentially executed
As process executes, it changes state. What are those states and what do they mean?
- new: The process is being created
- running: Instructions are being executed
- waiting: The process is waiting (blocked) for some event to occur
- ready: The process is waiting to be assigned to a processor
- terminated: The process has finished
execution
What is the diagram of process state?
- Process newly created blocks for input, New -> Ready
- Process picked to run becomes available, Ready -> Running
3 - Another process picked to run, Running -> Ready
4 - Process, Running -> Waiting
5 - Input, Waiting > Ready
6 - The process ends, Terminated
What is the process control block(PCB)
an array of structures maintained by the kernel
What do PCB entires contain?
information about the process’ state, including its program counter, stack pointer, memory allocation, the status of its open files, its accounting and scheduling information, etc
Everything that must be know to transition a process between running, ready and blocked states
What is the task control block?
Information associated with each process
(also called task control block)
What is PCB components and what do they mean?
- Process state – running, waiting, etc
- Program counter – location of instruction to next execute
- CPU registers – contents of all process-
centric registers - CPU scheduling information- priorities,
scheduling queue pointers - Memory-management information –
memory allocated to the process - Accounting information – CPU used,
clock time elapsed since start, time limits - I/O status information – I/O devices
allocated to process, list of open files
Which of the following would NOT likely be stored in a PCB entry?
❑ Current Time
❑ Process’s State
❑ # of Running processes
❑ Stack Pointer
❑ Scheduler’s State
❑ Current Time
List at least 3 elements that every process must have.
[Hint: what must be stored in order to completely halt then fully restore a running process?]
Process Identifier, Program Counter (PC), Process State
What is the point of multiprogramming?
Multiprogramming aims to have a process running at all times to maximize CPU utilization
Where does the process scheduler selects a ‘Ready’ process? Where do other ‘ready’ process wait? Where are 3 things a process will either be?
- The process scheduler selects a ‘Ready’ process for execution on the CPU
- All other ‘Ready’ processes wait in a Ready Queue
- Processes are either running, in the Ready Queue or waiting on I/O in an I/O Queue.
What is a short-term scheduler or Cpu scheduler?What is a Long-term scheduler (or job scheduler)?
Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU
* Sometimes the only scheduler in a system
* Short-term scheduler is invoked frequently (milliseconds) ⇒ (must be fast)
Long-term scheduler (or job scheduler)
– selects which processes should be brought into the ready queue
* Long-term scheduler is invoked infrequently (seconds, minutes) ⇒ (may be slow)
* The long-term scheduler controls the degree of multiprogramming
What can process either be describer as?
- I/O-bound process – spends more time
doing I/O than computations, many short
CPU bursts - CPU-bound process – spends more
time doing computations; few very long
CPU bursts
Describe CPU utilization with 20% I/0 wait, 50% IO wait, and 80% I/o wait
20% reaches higher cpu utilization faster
50 has is in-between 20% and 80% I/o wait(bingo closer to 20%), and *0% as a steady sloper
What is a I/O-bound process? What is CPU - bound process?
- A process that spends most of its time waiting on I/O is said to be an I/O-bound process.
- A process that spends most of its time running of the CPU is said to be a CPU-bound process.
What is the context or state of a process? Where is it stored? What does it include?
- The context or state of a process is all the information needed to suspend and later restore a running process
- The context is the information stored in the PCB and includes
- CPU registers & program counter
- memory management information
- process state
- Switching the CPU from a running process to another ready process amounts to
- performing a _____ ____ on the current
process. - performing a ____ ____ on the process to
resume.
state save
state restore
What is context switching?
- Switching from one process to another is known as a context switch.
Is context switching costly? What does the time depend on? What is it dependent on?
- Context switching is costly, typically requiring a few milliseconds of time during which no useful work is being done.
- Context switch time depends on the number of CPU registers that must be saved/restored.
- Context switch time highly dependent on hardware support. Some CPUs can load/store all registers with a single instruction.
- The creating process is called the ____ _____
- The created process is called the _____ ____
- All processes are identified by a ____ _____
parent process
child process
Process ID (PID) number
In Unix, we use the ____ system call to create a new process
* In Windows, use the ________ Win32
API to create a new process
* What typically one of two things happens after a new process is created
1.
2.
fork( )
CreateProcess( )
- The parent continues to execute concurrently with its child (or children)
- The parent waits until its child (or children) has terminated before continuing
How does fork() work? How is it implemented?
- fork() creates an exact clone of the calling process. The parent and child processes have the same memory image (program). The child’s initial address space (program + variables) is a copy of the parent’s.
- Usually, the child process executes an execv() system call to change its memory image and run a new program
- Some Unix implementations share the process image (program text) between parent and all its children. The child process may subsequently change its process image with a call to execv()
Unlike the Unix implementation, CreateProcess() combines the steps of forking and process image replacement. Thus, the parent and child’s
address spaces are distinct from the start.
What are the key differences between a
program and a process?
Program: Passive. It remains inactive until executed. The program instructions are stored on a secondary storage device like a hard drive.
Process: Active. It’s a dynamic entity that comes alive when the program is loaded into memory and starts executing. A process can be in various states like running, waiting, or terminated.
What are the typical conditions which terminate a process?
Typical conditions which terminate a process:
1. Normal exit (voluntary).
2. Error exit (voluntary).
3. Fatal error (involuntary).
4. Killed by another process (involuntary)
Unix → exit()
Windows → ExitProcess
What is waitpid()
- A parent can wait for its child process to exit by using the waitpid() system call
pid_t waitpid(pid_t pid, int *child_status, int options);
where, - pid is the process ID of the child we are waiting to complete.
- child_status is an integer returned by the terminated child process.
- options can be set to 0.
Typically, after executing a ____ function , the newly created child process will change its program.
* The ____ function can be used to do this.
fork()
execv()
Is fork a system call?
yes
What does the fork function return when it fails?
-1
All children of the parent process have the same process id?
False
How do you create a new process
unix fork
Every time you spawn a child process it inherits the parents stack from the parents
true