OS Midterm

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

FCFS execution parameters (scheduling)

First come first serve. Execute the full process in the order they arrive

What are the advantages of LKMs?

Functionality may be added or removed from the kernel without a reboot

Process Management

Mapping files onto secondary storage and manages free space

Below are two processes using the semaphores initialized as Q=1 and S=1. Which of the following is true regarding the execution of these processes? p0: wait(S); wait(Q); ... signal(S); signal(Q) p0: wait(Q); wait(S); ... signal(Q); signal(S)

P1 is subject to starvation. P0 is subject to starvation. P0 and P1 can result in deadlock

Process Management

Responsible for process creation, deletion, scheduling, synchronization and inter-process communication

RR execution parameters (scheduling)

Round Robin. Set the quantum to a unit (in our PS it was 20) and loop through the processes either executing the quantum or ending when the process is finished(whichever comes first) then moving on to the next available process.

Named Pipes

Named pipes persists across processes -operate as FIFO buffers or files -different processes can attach to the named pip to send and receive data. -Need to explicitly remove the named pipe

Deadlock Avoidance

for every resource request, the system determines if it would be in an unsafe state by granting that request. And thereby, will not grant it.

pthread_cond_destroy

kill a condition variable

Race Contition

when 2 or more processes access a shared resource, final result depends on the order of instructions that are executed

Race Condition

when two or more threads try to change the shared data at the same time.

synchronous

will make the request I/O and not continue until the command is completed. -often synchronous and blocking are used interchangeably

Which of the following conditions can you guarantee from the three processes below? P0: wait(&s1); x1; x2; wait(&s2); x3; P1: wait(&s1); y1; signal(&s2); y2; P2: z0; signal(&s1); z1; signal(&s1);

y1 will execute before x3

(T/F) The purpose of DMA is to free up the CUP during expensive I/O transfers

True

(T/F) a function defines within the monitor can access only those variables which are declared locally within the monitor

True

In batch scheduling of multiprogramming, once a process is started, it will control the CPU until its completion regardless of any idle CPU time

True

In co-operative scheduling, when a process needs to wait for resources, it will give up the CPU and be removed from the ready state

True

In multiprogramming, one or more processes are loaded in main memory to execute and only one process at a time is able to get the CPU while all the others are waiting in the ready queue

True

In multitasking, multiple processes are running concurrently and each process will share the CPU

True

Mutual exclusion is necessary to prevent race conditions

True

message passing IPC is generally slower than shared memory IPC

True

Signal handler always resides in the ____.

resides in the same code base as the program. 1) Program begins 2) Signal handler is installed 3) Execution continues 4) Signal is raised 5) Handler executes 6) Handler returns 7) Program execution continues

user mode (in user process)

return mode bit = 1

asynchronous

returns immediately (like non-blocking) -often asynchronous and non-blocking are used interchangeably -but in asynchronous write I/O, at some later time, the full number of bytes requested is transferred -subtle difference with blocking definition -can be implemented using signals and handlers.

In interprocess communication, a pipe may be used to ______.

send data unidirectionally between processes.

IPC cont

send() and receive() can be blocking/synchronous or non-blocking/asynchronous. Used to pass small messages. Advantage: OS handles synchronization. Disadvantage: slow.

Which of the following is considered as a mechanism of IPC? -Deadlock detection -pipes -none -shared memory -sockets

shared memory, pipes, sockets

Which of the following functions is used to attach shared memory to process?

shmat()

pthread _cond_signal

signal another thread and wake it up

pthread_cond_broadcast

signal multiple threads and wake them all up

To start an I/O operation, device driver loads the appropriate registers within the _________.

Device controller

Deadlock

(type of starvation)- when every process in the set is waiting for an event that can only be caused by another process in the set

What is true about VM's?

- A virtual machine executes on a host operating system and a hypervisor proves an API to the actual hardware. - The VM may supply an environment that is different than the actual host hardware - Applications running within the VM have an illusion that they are executing on a real machine

thread-safe code

- Functions correctly during simultaneous or concurrent execution by multiple threads - Global variables, static variables, and head variables are all not thread safe - Mechanisms to avoid non-thread safe code with global variables includes putting a mechanism in place to have the global variable only be accessed by one thread at a time

Mark all valid deadlock prevention schemes

- Number the resources and never request a lower number resource than the allocated ones. - Request and allocate all the resources required to a process before the process execution. -Release all resources before requesting a new resource.

choose all the options that are true about semaphores

- a basic semaphore can be implemented using an integer variable. - counting semaphores can range over an unrestricted domain. - two processes cannot execute wait() and signal() operations on the same semaphore at the same time. - if a semaphore is implemented using awaiting queue, deadlocks can occur between processes because of the signal() event.

which of the following is considered as a mechanism of inter process communication (IPC)

- shared memory - pipes - sockets

select all the necessary and sufficient conditions to cause deadlock

-> mutual exclusion (a resource is held in a non-sharable mode) -> hold-and-wait(a process currently holding at least 1 resource is requesting additional resources held my other processes) -> No preemption(a resource can be released only voluntarily by the process holding it) -> Circular wait(a process mist be waiting for a resource which is being held by another process, which in turn is waiting for the first process to release a resource)

What is the difference between Blocking vs non-blocking I/O system calls?

-Blocking I/O system calls put processes on a wait queue until I/O completes while blocking I/O system calls return immediately -Blocking I/O system calls are synchronous while non-blocking I/O system calls are asynchronous

re-entrant code

-If code behaves correctly when single thread is interrupted in the middle of executing. -Either no global variables, or have a temp variable to store the original state of the global before it is used in the code in order for it to be restored at the end

Which of the following is true regarding blocking and non-blocking I/O?

-In blocking I/O process waits until read or write competes. - Blocking I/O can also be called Synchronous I/O -Non-blocking system call can return after 0 bytes transferred. -Non-blocking I/O can also be called Asynchronous I/O

Advantages of Multiprocessor systems:

-Increased throughput: By increasing the number of processors, we expect to get more work done in less time. (less worth than linear). -Economy of scale: multiprocessor systems can cost less that equivalent multi single-processor systems because they can share peripherals, mass storage, and power supplies. -Increased reliability: if functions can be distributed properly among several processors, then the failure of one processor will not halt the system, only slow it down.

How to write a kernel module?

-Kernel Modules are written in the C language. -You must have a linux kernel source tree to build your module. - You must be running the same kernel version you built your module with to run it. -Linux kernel object: .ko extension.

How are the parameters passed to and results are returned from a system call?

-Parameters can be passed in registers -When there are more parameters than the registers, store the parameters in a block and pass the block address as a parameter to a register -Parameters can be pushed on and popped off the stack by the OS

What are the message passing IPC types?

-Pipes -Unix-domain sockets -internet domain sockets -message queues -remote procedure calls (RPC)

What are the methods in which you can pass parameters to the OS using system calls?

-Pointers -Registers -Stack

what are the different ways of doing IPC?

-Signals -interrupts -message passing -shared memory -remote procedure calls

which of the following are advantages of using LKM's

-When added to the OS, the kernel does not need to be rebuilt -editing and building are performed in user space -at build time the OS does not need to know about every possible device driver

select all the options that are true about pipes and sockets

-sockets in general use a client-server architecture. -pipes communicate by means of producer-consumer fashion. -named pipes require no parent-child relationship. -named pipes can be used over a network, while ordinary pipes cannot be used .

Applications, processes, and threads

-an application can consist of multiple processes, each on dedicated to specific task (UI, computation, communication, etc.) -Each process can consist of multiple threads -An application could thus consist of many processes and threads.

A process manager provides for

-creation/deletion of processes -synchronization of processes -monitoring and scheduling of processes.

What is an LKM?

-is an object file that contains code to extend a running kernel. -Can be loaded and unloaded from kernel on demand at runtime. -Offer an easy way to extend the functionality of the kernel without having to rebuild or recompile the kernel again. -Simple and efficient way to create programs that reside in the kernel and run in privileged mode. -Most of the drivers are written as LKMs. ** They reside in /lib/modules. ** lsmod : lists all kernel module that are already loaded

What are the different kinds of system calls?

-process control -file manipulation -device manipulation -information maintenance -communications -protection

system calls

-provide the means for a user program to ask the operating system to perform tasks reserved for the operating system on the user program's behalf. -Usually takes form of a TRAP to a specific location in the interrupt vector. This trap can be executed by a generic TRAP INSTRUCTION. -treated as a software interrupt by the hardware

Passing parameters in system calls

-register: simplest way. when there are more parameters that registers, store the parameters in a block and pass the block address as a parameter to a register -pointer: params stored in a block or table in memory and the address of the block passed as a parameter in a register -stack: parameters placed or pushed onto the stack by the program and popped off by the operating system

Transition from user to kernel mode

-user process executing => calls system call => trap mode bit = 0 => enters into the kernel where we execute the system call => return mode bit = 1 => return to user space where we get a return form the system call

What is the operating system responsible for with respect to memory management?

1) Keeping track of which parts of memory are currently being used and by whom 2) deciding which processes (or parts thereof) and data to move into and out of memory 3) allocating and deallocating memory space as needed

How does a user application access system code within the OS?

1) System call is made which places the system call id into a register and the trap instruction is thrown 2) Mode bit is switched into kernel mode from user mode 3) Kernel process a trap. The trap handler will index into jump table to find the handler for a specific system call and jump into the code 4) Mode bit is switched from kernel mode into user mode 5)Control is returned to the user space code following the trap invocation

What happens when you set the mode bit to 0?

1) The process can execute all machine instructions, even privilege instructions 2) ensure the user code can not modify the underlying OS data and data structures 3) can reference all memory locations 4) Kernel executes in this mode

system call process

1) The system call is made which places system call ID into a register and the trap instruction is shown 2) Mode bit is switched into kernel mode from user mode 3) Kernel processes a trap. The trap handler will index into jump table to find the handler for a specific system call and jump into the code 4) Mode bit is switched from kernel mode back to user mode 5) Control is returned to the user space following the trap invocation

What are the steps taken to start up a computer?

1) When the device is turned on, read ROM to locate the PRIMARY BOOT LOADER. 2)It then finds the MASTER BOOT RECORD and loads the SECONDARY BOOTLOADER into RAM. 3) It then asks the user or automatically loads the KERNEL into RAM

What happens when you set the mode bit to 1?

1) can only execute a subset of non privileged functions 2) can only reference a subset of memory locations 3) all applications run under user mode

What are the conditions that must be met for a deadlock to occur?

1) mutual exclusion 2) hold and wait 3) no preemption 4) circular wait

Solutions for race conditions

1) mutual exclusion 2) progress 3) Bounded waiting

What is the operating system responsible for with respect to process management?

1) scheduling processes and threads on the CPUs 2) creating and deleting both user and system processes 3) suspending and resuming processes 4) providing mechanisms for process synchronization 5) providing mechanisms for process communication

What is true about shared memory accessed by multiple threads?

1) shared memory can run into race conditions if it is not accessed in the correct order by the threads. 2)Shared memory has a serious disadvantage of leaving processes to starve since a single thread can hog the resource by never letting the other threads access it. 3)Shared memory provides an extremely fast way to communicate large or small amounts of data because any data that is written by one thread to a shared memory region, can be read immediately by any other thread that had the privilege to read from that memory location.

how should we approach deadlock elimination?

1) we can eliminate deadlock by terminating all the processes that are deadlocked. 2) we can eliminate deadlock by terminating one process at a time until a deadlock cycle is eliminated. 3) we can eliminate deadlock by informing the operator that a deadlock has occurred and lets the operator deal with the deadlock manually. 4) we can eliminate deadlock by successively preempting some resources from processes and giving these resources to other processes until the deadlock cycle is broken

A counting semaphore is initialized to 15. 8 wait operations and 7 signal operations were completed on this semaphore. What is the resulting value of semaphore?

14 (15 - 8 + 7 = 14)

A system has 3 programs and each program requires 3 units of a resource R1 for its operation. Select the minimum number or R1 units required such that the deadlock will never arise.

7

What is a device Minor Number?

A number to differentiate all the devices belonging to a specific device driver

A global variable is initialized and is used in two different functions without using a temp variable. What could this potentially lead to?

A race condition

hardware abstraction

An OS sits between the applications that we write and the hardware. It essentially provides a high level view of the system so that programs can be written easily without the programmer having to worry about the nitty-gritty details of the hardware.

What is a device Major Number?

A unique number for every device driver

Deadlock may occur when (select all that apply)

A wait() is followed by a wait() instead of a signal() or when a programmer reverses the order of wait() and signal()

Threads vs. Processes

Advantages of multithreading: -sharing between threads is easy -faster creation Disadvantages of multithreading: -ensure threads-safety -bug in one thread can bleed to other threads, since they share the same address space -threads must compete for memory. Considerations -Dealing with signals in threads is tricky -all threads mush run the same program -sharing of files, users, etc.

Memory Management

Allocating and deallocating free space for processes and keeping track of what space is being used by every process

Critical Section

Area in code where processes access shared resources

Von Neumann Architecture

CONNECTION: Part of Memory Management: The CPU reads instructions from main memory during the instruction-fetch cycle an both reads and writes data from main memory during the data-fetch cycle (on a von Neumann architecture)

Deadlock Detection

Deadlocks are allowed to occur and stem will examine itself periodically to detect detection and correct it.

What is a DMA?

Direct Memory Access. This is used when interrupt driven I/O when you need to move a bulk amount of data, such as a disk I/O. After setting up buffers, pointers, and counters for the I/O device, the device controller transfers an entire block of data directly to or from its own buffer storage to memory with no intervention bu the CPU. CPU is available to accomplish other work.

Context Switch

During a _________ , the state of the process is saved and written to RAM and the process state for the new process which gets to run is loaded from RAM and the new process starts running.

EDF (with preemption) execution parameters (scheduling)

Earliest deadline first. When a new process arrives or a process ends check to see which one has the earliest deadline and switch to that process

(T/F) Fault and abort classes of exceptions are potentially recoverable forms of exceptions

False

(T/F) In general, with N processes sharing N semaphores, the potential for deadlock decreases as N grows larger

False

(T/F) Signaling with a condition variable is the same as signaling with a semaphore

False

(T/F) The OS is aware of user-space threads

False

What is the interface between the virtual machine and the host machine is called?

Hypervisor

Who initiates a DMA transfer

I/O devices

Protection

In a multiprogramming environment, each process that runs on the OS has its own set of resources and other processes cannot access those resources. The OS controls the access to all resources from internal and external access.

Resource Management

In a multiprogramming environment, the OS allows multiple applications to share resources, protects apps from each other, and improves performance by efficient utilization of resources.

The Kernel identifies a driver with a _________.

Major Number

What is IPC?

Inter-process communication refers specifically to the mechanisms an operating system provides to allow processes it manages to share data. Typically, applications can use IPC categorized as clients and servers, where the client requests data and the server responds to client requests. Signals and Message passing through pipes and sockets.

Which of the following is a disadvantage of IPC message passing?

Is is slow. OS is involved in each IPC operation for control signaling and possibly data as well.

Which of the following is TRUE regarding the relationship between processes and threads?

It takes far less time to create a new thread in an existing process than to create a new process.

What is the responsibility of the OS

Memory management, process management, file system, device management (not compiling a program)

Starvation

Possibility that a process never gets to run. Deadlock is a type of starvation

Deadlock Prevention

Preventing on of the four necessary and sufficient conditions from occurring

IPC via Sockets

Process 1 in Computer 1 sends messages as streams of data to process 2 in computer 2 and then can be returned on the same bi-directional socket to process/computer 1. communication can be via NETWORK.

IPC via Pips

Process 1 sends messages as streams of data. through a unidirectional pipe to process two, which can go through a different pipe to return to process 1

how do IPC's work

Process A: send() to main memory process B: receive() the message process A sent to main memory

In a process control block which of the following is used to retrieve the information on the next instruction to be executed?

Program counter

I/O management

Provides a device driver interface for applications for easy access to any external device without knowing the internal details of the hardware

SJF execution parameters (scheduling)

Shortest Job First. Every time a process ends or a new process arrives, check to see which has a longer burst time and execute the process with the shortest burst time. **note: it is not how much is left in the burst, it is the total length of the burst that is compared

A system call usually takes the form of a _____ to a specific location in the interrupt vector. When is system call is executed, it is treated by the hardware as a ________.

TRAP SOFTWARE INTERTUPT

The process of indexing into the trap table to jump to the trap handler routine is called _________.

Trap instruction

Dining Philosophers Problem

The idea that resources must be shared among several processes in a DEADLOCK and starvation free manner

(T/F) A mouse is more likely to be polling an I/O device while a hard drive is more likely to be an interrupt-driven I/O device.

True

(T / F) A MONITOR is an object designed to be accessed from multiple threads. The member functions or methods of a monitor object are mutually exclusive

True

(T/F) A DMA sends an interrupt to the CPU when it is finished.

True

(T/F) DMA is made possible through specialized hardware

True

What is passed through an interrupt?

There is not much information. Only that an event has occurred.

How do remote procedure calls (RPCs) work?

When the user calls the kernel to send RPC message to a procedure, the kernel then sends a message to matchmaker to find port number. An answer is now received by the kernel(client), which then places the answer in user RPC message and the kernel actually sends a remote procedure call. This is then received by a daemon that is listening and it processes the request and sends the output back to the kernel, which then passes the reply to the user.

Every process state in an OS is represented by

a process control block

In the child process, the fork() command should return...

a value of 0

pthread_cond_wait

block waiting for a signal

Define blocking

blocking system call: -process put on wait queue until I/O read or write completes -I/O command succeeds completely or fails

pthread_cond_init

cread a condition variable

part of the program where a shared resource is accessed is _________

critical section

What problem can arise when implementing synchronization with semaphores?

deadlock

Single-threaded process

has one program counter specifying the next instruction to execute. One instruction at a time is executed.

Progress

if no process is executing in critical section and some processes wish to enter critical section, then only those processes that wish to enter can participate on which will enter the critical section next

Mutual exclusion

if process P is executing in its critical section, no other processes can be executing in their critical sections, one process has access to a locked resource (CPU), usually implemented with booleans

Concurrency is

interleaving of processes to simulate parallelism

Define non-blocking

non-blocking system call: -a write or red returns immediately with partial number of bytes transferred (possibly zero) - e.g. keyboard, mouse, network sockets. -makes all the application more complex. -> not all the data may have been read or written in single call -> have to add additional code to handle this, like a loop.

In RPC, communication processes can be ____

on the same host or on different remote hosts.

Traditional/anonymous pipe

only exists transiently between the two processes connected by the pipe. As soon as these processes complete, the pipe disappears.

critical section

part of program where shared resource is accessed

example of system call with standard c library

printf("hello world") in user moder -> standard C library -> kernel mode -> write() -> write() system call -> standard C library -> user mode C program

mutual exclusion

the idea of which we want to prevent one process from accessing a resource while the current process is modifying said shared resource.

what does the fork() command do?

the shall executes this to start a new process. Then, the selected program is loaded into memory via an exec() system call, and the program is executed.

Bounded waiting

there exists a bound/limit on the number of processes that can enter their critical sections

Is the function f() thread safe? Is f() reentrant? lock mutex; int g = 0; inf f(int i){ int x = g; x = x-2; x = i; x = x*x; return x; }

thread-safe, thread-reentrant

The ____ instruction interrupts the OS to signal to switch into ____ mode, which is needed for a system call.

trap : kernel

kernel mode (in kernel)

trap mode bit = 0

(T/F) Local variables of a monitor can be accessed only by its local functions

true

Shared memory IPC can lead to synchronization problems

true

In order to limit what user software actions may do on a system, the kernel operates in a seperate kernel space and the user code operates in user space

true regarding the code that runs in user space and kernel space

The kernel ensures that the user code cannot modify the underlying OS data and data structures

true regarding the code that runs in user space and kernel space

The user code shall NOT allocate or deallocate memory without making a request to the kernel

true regarding the code that runs in user space and kernel space


संबंधित स्टडी सेट्स

Marketing 3343 Final Exam Review -Murdock 252-

View Set

Soil 3:Weathering, Soil, and Mass Movements

View Set

Chapter 5: Innovation and Entrepreneurship

View Set

Small Test - Economics EOC (GSE) UPDATED Domain: International Economics

View Set