Operating Systems: Process Abstraction and Management - COP 4600, Exams of Advanced Education

A comprehensive overview of process abstraction and management in operating systems, focusing on key concepts like process states, process control blocks, and process api. It delves into the mechanisms and policies involved in managing processes, including scheduling, context switching, and memory allocation. The document also explores the role of the stack and heap in process execution and the importance of file descriptors in unix-like systems. It includes explanations of various concepts and their practical applications, making it a valuable resource for students studying operating systems.

Typology: Exams

2024/2025

Available from 03/02/2025

Smartsolutions
Smartsolutions 🇺🇸

3

(4)

18K documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COP 4600 WITH COMPLETE SOLUTIONS 100%
CORRECT LATEST UPDATE
Chapter 4 - The Abstraction: The Process /
Processes
Process /
Job - ANSWER An executing program.
The abstraction provided by the OS of an executing program.
Virtualizing - ANSWER Running a virtual instance of a computer system in a layer
abstracted from the actual hardware.
Time Sharing (CPU) - SOLUTION By running one process, then stopping it and running
another, and so forth, the OS can promote the illusion that many virtual CPUs exist when
in fact there is only one physical CPU (or a few).
This is a straightforward approach that allows users to have as many processes
concurrent as they may want; the possible cost is performance, as they will execute
more slowly in case the CPU(s) have to be shared.
The basic concept is simple: run one process for a little time, then run another one, and
so on. In this way, by time sharing the CPU, virtualization is achieved.
Space Sharing (CPU) - ANSWER Where a resource is divided, in space among those
desiring its use.
Disks are obviously a spaced shared resource; once a block is assigned to a file it is
usually not assigned to another file until the user deletes the original.
Mechanisms - ANSWER Low-level methods or protocols for providing a needed portion
of functionality.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Operating Systems: Process Abstraction and Management - COP 4600 and more Exams Advanced Education in PDF only on Docsity!

COP 4600 WITH COMPLETE SOLUTIONS 100%

CORRECT LATEST UPDATE

Chapter 4 - The Abstraction: The Process /

Processes

Process /

Job - ANSWER An executing program.

The abstraction provided by the OS of an executing program.

Virtualizing - ANSWER Running a virtual instance of a computer system in a layer abstracted from the actual hardware.

Time Sharing (CPU) - SOLUTION By running one process, then stopping it and running another, and so forth, the OS can promote the illusion that many virtual CPUs exist when in fact there is only one physical CPU (or a few).

This is a straightforward approach that allows users to have as many processes concurrent as they may want; the possible cost is performance, as they will execute more slowly in case the CPU(s) have to be shared.

The basic concept is simple: run one process for a little time, then run another one, and so on. In this way, by time sharing the CPU, virtualization is achieved.

Space Sharing (CPU) - ANSWER Where a resource is divided, in space among those desiring its use.

Disks are obviously a spaced shared resource; once a block is assigned to a file it is usually not assigned to another file until the user deletes the original.

Mechanisms - ANSWER Low-level methods or protocols for providing a needed portion of functionality.

Context Switch - ANSWER A time-sharing mechanism used in all modern OSes.

It provides the OS with the capability of taking a currently running program off the CPU and putting another program on that CPU

Policies - ANSWER Methods/algorithms for making some sort of decision with the OS.

As an example, considering multiple runnable programs are contending to run on a CPU, which one should the OS choose to run? The OS would use a scheduling policy to do so, almost surely leveraging historical data - e.g., which program has received the most CPU time over the past minute? -, workload knowledge - e.g., what classes of programs are running -, and performance metrics - e.g., is the system optimizing for interactive performance, or throughput?.

Machine State - ANSWER What a program can read or update during execution.

At any moment in time, which part of the machine is relevant for the execution of that program?

Memory - ANSWER A part of machine state consisting of a process.

Instructions lie in memory; the data that the running program reads and writes sits in memory as well. Thus the memory that the process can address-called its address space-is part of the process.

Address Space - ANSWER The memory that the process can address.

Registers - ANSWER Part of the process's machine state.

Many instructions explicitly read or update registers and thus clearly they are important to the execution of the process

other controls that are possible. For example, most operating systems provide some kind of method to suspend a process (stop it from running for a while) and then resume it (continue it running).

Status: There are usually interfaces to get some status information about a process as well, such as how long it has run for, or what state it is in.

Load - ANSWER The first thing that the OS must do to run a program is to load its code and any static data (e.g., initialized variables) into memory, into the address space of the process.

Disk /

Disc /

Flash-Based SSD - ANSWER Where a program first resides in some form of executable format.

The process of loading a program and its static data into memory requires the OS to read those bytes from disk and place them in memory somewhere.

Eagerly (Loading Process) - ANSWER The loading process is performed all at once before the actual running of the program.

Lazily (Loading Process) - ANSWER Loading pieces of code or data only as they are needed during program execution.

Run-Time Stack /

Stack - ANSWER Once the code and static data are loaded into memory, there are a few other things the OS needs to do before running the process. Some memory must be allocated for the program's run-time stack (or just stack).

C programs rely on the stack for local variables, function parameters, and for return addresses; the OS sets aside this memory and hands it to the process.

The OS will also likely initialize the stack with arguments; more specifically, it will fill in the parameters to the main() function, i.e., argc and the argv array.

Heap - ANSWER In C the heap is used for dynamically allocated data which is requested directly; programs request such space directly by calling malloc() and free it directly by calling free(). The heap is required for data-structures like linked-lists, hash-tables, trees and most other data-structures of interest. This heap is small at the start; as a program runs, and makes request after request for more and more memory via the malloc() library API, the OS may get involved and give this process more memory to help satisfy such calls.

File Descriptors - SOLUTION By default, each process in UNIX-like systems has three open file descriptors bound to standard input, output, and error, respectively. These three descriptors enable programs to perform easy reads of input from the terminal and print outputs onto the screen.

Process States - SOLUTION Running: During this state, a process is on the processor. In other words, it is executing instructions.

Ready: In this state, a process is ready to run but for some reason, the OS has chosen not to run it at this given moment.

Blocked: In the blocked state, a process has performed some sort of operation such that it is not ready to run until some other event occurs. Common example: When a process issues an I/O request to a disk, it becomes blocked and hence some other process can use the processor.

Scheduled /

Scheduling - ANSWER When a process is moved from ready state to running state.

Descheduled /

Descheduling - ANSWER When a process is moved from the running state to the ready

Chapter 5 - ANSWER Interlude: Process API /

Process API

fork() System Call - ANSWER Used to create a new process.

The UNIX fork() system call creates a new process. The creator is called the parent; the newly created process is called the child. As sometimes occurs in real life, the child process is a nearly identical copy of the parent.

Process Identifier (PID) - ANSWER In UNIX systems, in naming the process if one wants to do something with the process, such as-for example-stop it from running.

Each process has a name; in most systems, that name is a number known as a process ID.

Child Process /

Parent Process - ANSWER The newly-created process from the creating parent process.

As is often the case in life, the child process is very similar to the parent.

Deterministic Output - ANSWER When an input will always cause the same output with absolutely no variation; not all programs or processes are deterministic.

An indeterminate program has one or more race conditions; the output of the program differs from run to run, depending on which threads ran when. The result is hence not predictable, which is normally what we want from computer systems.

CPU Scheduler - ANSWER Determines which process runs at a given moment in time; because the scheduler is complex we cannot usually make strong assumptions about what it will choose to do, and hence which process will run first.

Non-Deterministic Output - ANSWER When an input will not always produce the same output each time.

We can't normally make good assumptions about what it will decide to do, and therefore which will run first.

wait() System Call - ANSWER Sometimes, it is quite handy for a parent to wait for a child process to finish up what it's doing. This job is done with the wait() system call (or its fuller brother waitpid()).

Wait() system call allows the parent to wait for its child to finish execution

Exec() System Call - ANSWER This system call is useful especially when you want to run a program different than the calling program.

Exec() Family of system calls allows the child to break out from its similarity with the parent and execute a completely new program.

Shell - ANSWER A UNIX shell typically uses fork(), wait(), and exec() to execute user request; fact that fork() and exec() are separate allows the shell to do input/output redirection, pipes, and all sorts of cool things without requiring any modifications to the programs being executed.

Prompt - ANSWER A user program; it sits there waiting for you to enter something through it (in most cases, a command).

Standard Output(Redirected / Redirecting) - ANSWER The normal/expected output of a program. It can be redirected to an output file instead of being displayed onto the screen.

Signal - ANSWER What system calls use to call a process's directives.

the protocol of limited direct execution which runs programs efficiently but without loss of OS control.

User Mode - ANSWER Code running in user mode has its hands somewhat tied. For example, if a process is running in user mode, it cannot request that I/O be done; such requests would cause the processor to raise an exception; the OS would likely then kill the offending process.

Kernel Mode - ANSWER What the operating system (or kernel) runs in. In this mode, code that runs can do what it likes, including privileged operations such as issuing I/O requests and executing all types of restricted instructions.

System Call - ANSWER When a user program or user process wishes to perform some kind of privileged operation, such as reading from a disk, it perform a system call.

System calls - a means for the kernel to judiciously make available to user programs certain important pieces of its functionality, such as reading/writing from/to the file system, creating/destroying processes, sending/receiving information from/to other processes, and allocating more memory.

Trap Instruction - ANSWER Used to execute a system call.

This instruction simultaneously jumps into the kernel and raises the privilege level to kernel mode; once in the kernel, the system can now perform whatever privileged operations are needed (if allowed), and thus do the required work for the calling process.

Return-From-Trap Instruction /

Return From Trap Instruction - ANSWER Returns into the calling user program while simultaneously reducing the privilege level back to user mode.

Trap Table - ANSWER Dictates which code is executed when a trap instruction has occurred. The kernel sets up the trap table during boot time.

System-Call Number - ANSWER There is usually a number assigned to each system call in order to specify which system call.

Protection - ANSWER Allows the user to request a particular service via a number and not specify an exact address to jump to.

Privileged Operation - ANSWER If you try to execute this instruction in user mode, the hardware will not allow you, and the offending program is terminated.

Limited Direct Execution (LDE) Protocol /

Limited Direct Execution Protocol /

LDE Protocol - ANSWER A two-phase protocol.

In the first one-at boot time, the kernel initializes the trap table, and the CPU remembers its location for subsequent use. The kernel does so via a privileged instruction.

In the latter (when running a process), the kernel does a few things to setup (e.g., allocates a node on the process list, allocates memory), and then issues a return-from-trap instruction in order to start running the process; this action puts the CPU in user mode, and starts executing the process. When the process wants to execute a system call, it traps back into the OS, which handles it and once again returns control via a return-from-trap to the process. The process then finishes off its work, and returns from main(); this usually will return into some stub code which will properly exit the program (say, by calling the exit() system call, which traps into the OS). At this point, the OS cleans up and we are done.

Cooperative Approach - ANSWER In this style, the OS trusts the processes of the system to behave reasonably. Processes that run for too long are assumed to periodically give up the CPU so that the OS can decide to run some other task.

Most processes voluntarily give up the CPU to the operating system by making system calls. Many such systems also have an explicit yield system call, that does nothing

restore a few for the soon-to-be-executing process (from its kernel stack).

By doing this, the OS ensures that when the return-from-trap instruction is eventually executed, instead of resuming the process that was running, the system resumes execution of another process.

Sometimes the OS, during a timer interrupt or system call, may want to switch out from running the current process and run some other process, a low-level technique called context switch.

Disable Interrupts - ANSWER One simple thing an OS might do is disable interrupts during interrupt processing; doing so ensures that one interrupt is being handled, no other one will be delivered to the CPU.

Chapter 7 - ANSWER Scheduling: Introduction /

CPU Scheduling

Scheduling Policies /

Disciplines - ANSWER

Workload - ANSWER The processes running in the operating system.

Turnaround Time - ANSWER A job's turnaround time is considered to be the time at which the job completes minus the time at which the job arrived in the system. More formally, the turnaround time T_turnaround is:

T_turnaround = T_completion - T_arrival

Turnaround time is a performance metric.

Fairness - ANSWER Allowing as many jobs to run as possible.

First In, First Out (FIFO) Scheduling /

First In, First Out Scheduling

FIFO Scheduling /

First Come, First Served (FCFS) Scheduling /

First Come, First Served Scheduling /

FCFS Scheduling - ANSWER Processes are executed in the order they are summoned. It is straightforward to implement but suffers from the convoy effect.

Convoy Effect - ANSWER Where a number of relatively short potential consumers of a resource get queued behind a heavyweight resource consumer.

Shortest Job First (SJF) Scheduling /

Shortest Job First Scheduling /

SJF Scheduling - ANSWER Processes are run from shortest to longest.

Non-Preemptive Schedulers - ANSWER Systems that would run each job to completion before considering whether to run a new job.

This method of batch computing is largely archaic.

Preemptive Schedulers - ANSWER Systems that are willing to stop one process from running in order to run another by using a context switch.

Virtually all modern schedulers are preemptive.

Shortest Time-to-Completion First (STCF) Scheduling /

Shortest Time-to-Completion First Scheduling /

STCF Scheduling /

Preemptive Shortest Job First (PSJF) Scheduling /

Preemptive Shortest Job First Scheduling /

MLFQ Scheduling - Operating contains queues with different priority levels. The jobs in the highest priority queue are executed first.

Balances turnaround time with perceived response time to user.

Rules:

Rule 1 If Priority(A)>Priority(B) A runs; B doesn't.

Rules: · Rule 2: If Priority(A) = Priority(B), A & B run in round-robin fashion using the time slice (quantum length) of the given queue. · Rule 3: On arrival, a job joins the highest priority-that is, topmost queue.

-Rule 4: If a job utilizes its entire time slice from a particular level, without regard to how many times it relinquishes the CPU, it then loses one priority level (i.e., move down one queue).

-Rule 5: After some time period S, transfer all jobs in the system to the topmost queue.

Starvation - ANSWER If there are "too many" interactive jobs in the system, they will combine to consume all CPU time, and thus long-running jobs will never receive any CPU time they starve.

Gaming the scheduler /

Game the scheduler - ANSWER Doing something sneaky to trick the scheduler into giving more than the fair share of the resource.

Parameterise ANSWER Determine the number of queues, the size of the time slices, the frequency of priority boosting to avoid starvation and to take account of changes in behaviour.

Ousterhout's Law ANSWER When it is possible, it is generally very useful to avoid voo-doo constants.

The typical result: a configuration file containing lots of default values for parameters which a sophisticated administrator will tweak if everything isn't behaving quite as it should.

Chapter 26 - ANSWER Concurrency: An Introduction /

Concurrency and Threads

Thread - ANSWER An abstraction for a single running process. It allows overlap of I/O and other activities within a single program, and is a major reason to use threads over processes.

Multi-Threaded Program - ANSWER A multi-threaded program has more than one point of execution (i.e., several PCs, each of which is being fetched and executed from).

Thread Control Blocks (TCBs) - ANSWER Keeps track of the status of each thread of a process.

Parallelism /

Parallelization - ANSWER The technique of transforming a mono-threaded program into a program that executes on more than one CPU by making use of one thread per CPU.

One of the basic reasons for the use of threads.

Disassembler - ANSWER When you run a disassembler on an executable, it shows you the assembly instructions that make up the program.

Race Condition /

Data Race - ANSWER The result is based on race condition of timing of execution. With some bad luck ie, context switches occurring at untimely points in execution we get the wrong answer. Actually we may get a different answer every time.

This is an example of indetermination.

A race condition, or data race, occurs when several threads of execution enter the critical section around the same time; both try to update the shared data structure,

should start running in. It returns a pointer (i.e. a void pointer, "void *").

Procedure Call - ANSWER A way to create a thread.

Condition Variable - ANSWER A major component of any threads library, and certainly the case with POSIX threads.

Condition variables are useful when there is the need for some kind of signaling between threads in the case when one is waiting for another to do something before it can proceed.

A condition variable is an explicit queue that threads can put themselves on when some state of execution-i.e., some condition-is not as desired; some other thread, when it changes said state, can then wake one-or more-of those waiting threads and thus allow them to continue. Signaling on a condition variable is the method by which one thread allows another thread to continue.

-Initialize locks and condition variables

-Check your return codes

-Be careful with how you pass arguments to, and return values from, threads.

-Each thread has its own stack

-Always use condition variables to signal between threads

-Use the manual pages

Chapter 28 - ANSWER Locks /

Locks

Lock /

Mutex (POSIX) - ANSWER A lock is just a variable, and thus to use one, you must declare a lock variable of some kind (such as mutex above). This lock variable (or just "lock" for short) holds the state of the lock at any instant in time.

It is either available (or unlocked or free) and thus no thread holds the lock, or acquired (or locked or held), and thus exactly one thread holds the lock and presumably is in a critical section.

In POSIX, it is called a mutex, from (mut)ual (ex)clusion.

Owner (Lock) - ANSWER The thread that acquires the lock and enters the critical section.

Coarse-Grained Locking Strategy - ANSWER One large lock used anytime any critical section is accessed.

Fine-Grained Locking Strategy - ANSWER Protecting disparate data and data structures with different locks, thus allowing more threads to be in locked code at once.

Spin-Waiting - ANSWER A performance problem whereby when a thread waits to acquire a lock that is already held it results in it infinitely checking the value of the flag.

Test-and-Set Instruction /

Atomic Exchange Instruction - SOLUTION It returns the old value pointed to by the "old_ptr", and simultaneously updates said value to "new".

The reason it is known as "test and set" is because you can "test" the old value that is returned during the execution of this instruction, while simultaneously "setting" the memory location to a new value. This instruction can build a spin lock.

Dekker's Algorithm - ANSWER A solution to the concurrency program that uses only loads and stores.

Peterson's Algorithm - ANSWER An enhancement of Dekker's algorithm. The idea is to ensure that two threads are never inside a critical section at the same time.