cs149 extra

¡Supera tus tareas y exámenes ahora con Quizwiz!

How many read/write heads are there per platter? a.1 b.2 c.3 d.4

2 b

_____ is the dynamic storage-allocation algorithm which results in the smallest leftover hole in memory. 1.A) First fit 2.B) Best fit 3.C) Worst fit 4.D) None of the above

2.B) Best fit

_____ is the dynamic storage-allocation algorithm which results in the largest leftover hole in memory. 1.A) First fit 2.B) Best fit 3.C) Worst fit 4.D) None of the above

3.C) Worst fit

What is true about the timer interrupt? 1.The OS sets up a hardware timer that generate an interrupt every N milliseconds. 2.That interrupt is delivered to the kernel and user-code is interrupted. 3.The CPU knows what code to run when the timer interrupt occurs. The CPU scheduler will run next to schedule another process. 4.All of the above

4(D) all of the above 1.It works like any other hardware interrupt. For example your disk will force a switch to the kernel when it has completed an IO.

How does the OS communicate to an application process? A)Signals B)Bus C)Hardware interrupts D)Ethernet

A APUE: Signals are a technique used to notify a process that some condition has occurred. For example, if a process divides by zero, the signal whose name is SIGFPE (floating-point exception) is sent to the process. The process has three choices for dealing with the signal. 1. Ignore the signal. This option isn't recommended for signals that denote a hardware exception, such as dividing by zero or referencing memory outside the address space of the process, as the results are undefined. 2. Let the default action occur. For a divide-by-zero condition, the default is to terminate the process. 3. Provide a function that is called when the signal occurs (this is called ''catching'' the signal). By providing a function of our own, we'll know when the signal occurs and we can handle it as we wish. Many conditions generate signals. Two terminal keys, called the interrupt key— often the DELETE key or Control-C—and the quit key—often Control-backslash—are used to interrupt the currently running process. Another way to generate a signal is by calling the kill function. We can call this function from a process to send a signal to another process. Naturally, there are limitations: we have to be the owner of the other process (or the superuser) to be able to send it a signal.

What is the name of the signal handler function in this code? A)sig_int B)signal C)err_sys D)main #include "apue.h" #include <sys/wait.h> static void sig_int(int); int main(void) { char buf[MAXLINE]; pid_t pid; int status; if(signal(SIGINT, sig_int) == SIG_ERR){ err_sys("signal error"); } printf("%% "); while(fgets(buf, MAXLINE, stdin) != NULL) { if(buf[strlen(buf) - 1] == '\n') { buf[strlen(buf) - 1] == 0; } if((pid = fork()) < 0) { err_sys("fork error"); } else if (pid == 0) { execlp(buf, buf, (char *)0); err_ret("couldn't execute: %s", buf); exit(127); } if ((pid = wait(pid, &status, 0)) < 0) { err_sys("waitpid error"); } printf("%% "); } exit(0); } void sig_int (int signo) { printf("interrupt\n%% "); }

A Signals are a technique used to notify a process that some condition has occurred. For example, if a process divides by zero, the signal whose name is SIGFPE (floating-point exception) is sent to the process. The process has three choices for dealing with the signal. 1. Ignore the signal. This option isn't recommended for signals that denote a hardware exception, such as dividing by zero or referencing memory outside the address space of the process, as the results are undefined. 2. Let the default action occur. For a divide-by-zero condition, the default is to terminate the process. 3. Provide a function that is called when the signal occurs (this is called ''catching'' the signal). By providing a function of our own, we'll know when the signal occurs and we can handle it as we wish. Many conditions generate signals. Two terminal keys, called the interrupt key— often the DELETE key or Control-C—and the quit key—often Control-backslash—are used to interrupt the currently running process. Another way to generate a signal is by calling the kill function. We can call this function from a process to send a signal to another process. Naturally, there are limitations: we have to be the owner of the other process (or the superuser) to be able to send it a signal.

What is the output? # include<stdio.h> # include<stdlib.h> void fun(int *a) { a = (int*)malloc(sizeof(int)); } int main() { int *p; fun(p); *p = 6; printf("%dn",*p); return(0); } _______ A) May not work B) Works and prints 6

A fun() makes a copy of the pointer, so when malloc() is called, it is setting the copied pointer to the memory location, not p. p is pointing to random memory before and after the call to fun(), and when you dereference it, it will crash. If you want to add memory to a pointer from a function, you need to pass the address of the pointer (ie. double pointer).

Shortest Job First (SJF)

A NONPREEMPTIVE scheduling algorithm that deals with each user or task based on the getting the smaller ones out of the way. what if not all jobs arrive at the same time, we won't know whats small and whats not

Shortest Time-to-Completion First (STCF)

A new job enters the system: Determine the projected duration of the remaining jobs and new job Schedule the job which has the least time left Always run job that will complete the quickest

What problem do you see with this program? A)The file temp.txt could be left open when user does Ctrl+C B)It removes temp.txt C)It removes temp.txt after closing the file D)It returns 0 int main(void) { FILE *psFile; psFile = fopen("temp.txt", "w"); ... fclose(psFile); remove("temp.txt"); return 0; }

A) A)The file temp.txt could be left open when user does Ctrl+C Program generates lots of temporary data - Stores the data in a temporary file -Must delete the file before exiting

We use malloc and calloc for A) Dynamic memory allocation B) Static memory allocation C) Both dynamic and static memory allocation D) None of the above

A) Dynamic memory allocation _____ A Both Calloc() and Malloc() are used for dynamic memory allocation. calloc() gives you a zero-initialized buffer, while malloc() leaves the memory uninitialized.

What does the code do? A)Specifies a handler for SIGINT signal B)Specifies a handler for any signal C)Removes the signal handlers D)None of the above #include <stdio.h> #include <stdlib.h> #include <signal.h> static void myHandler(int iSig) { printf("In myHandler with argument %d\n", iSig); } int main(void) { int iRet; struct sigaction sAction; sAction.sa_flags = 0; sAction.sa_handler = myHandler; sigemptyset(&sAction.sa_mask); iRet = sigaction(SIGINT, &sAction, NULL); assert(iRet == 0); printf("Entering an infinite loop\n"); for (;;) ; return 0; }

A) Specifies a handler for SIGINT signal

What is the output of this program? #include<stdio.h> #include<stdlib.h> int main() { int *ptr; ptr = (int *)calloc(1,sizeof(int)); if (ptr != 0) printf("%d\n",*ptr); return 0; } ________ A)0 B)-1 C)Garbage value D)none of the mentioned

A)0

Paging avoids external fragmentation and the need for compaction, two problems that plague contiguous memory allocation. A)True B)False

A)True

Paging is a memory-management scheme that permits a process's physical address space to be noncontiguous. A)True B)False

A)True

What is the return type of malloc() or calloc()? A)void * B)Pointer of allocated memory type C)void ** D)int *

A)void * _______ A malloc() and calloc() return void *. you may get warning in C if you don't type cast the return type to appropriate pointer.

Benefits of Paging

Address space of processes can be noncontiguous in ram processes can be anywhere and can be allocated with free memory available avoid the need for merging, which is costly

The PID of the kernel process is A. Undefined B. 0 C. 1 D. 3

B PID of the kernel process is 0. There are two tasks with especially distinguished process IDs: swapper or sched has process ID 0 and is responsible for paging, and is actually part of the kernel rather than a normal user-mode process. Process ID 1 is usually the init process primarily responsible for starting and shutting down the system. The process identifier (PID) is a number used by most operating system kernels such as those of UNIX, mac OS and Microsoft windows to uniquely identify an active process. Process 0 is a special process that is created when the system boots; after forking a child process (process 1), process 0 becomes the swapper process.

In UNIX, the file name and file size are stored in the file itself. a) True b) False

B Explanation: A UNIX file's size is not stored in the file, nor its name. All this information is stored separately in a separate area of hard disk.

What is the problem with following code? ________ #include<stdio.h> int main() { int *p = (int *)malloc(sizeof(int)); p = NULL; free(p); } _______ A) Compiler Error: free can't be applied on NULL pointer B) Memory Leak C) Dangling Pointer D) The program may crash as free() is called for NULL pointer.

B free() can be called for NULL pointer, so no problem with free function call. The problem is memory leak, p is allocated some memory which is not freed, but the pointer is assigned as NULL. The correct sequence should be following: free(p); p = NULL;

Buffer cache helps to a) Store data b) Improved read/write performance c) Allocate memory d) None of the mentioned

B https://lwn.net/Articles/457667/

What best describes a signal? a)any hardware device generated interrupt b) software or hardware generated event, mediated by kernel c) any interrupt always generated by a user d) none of the mentioned

B https://stackoverflow.com/questions/45485093/signal-vs-exceptions-vs-hardware-interrupts-vs-traps

Which of the following is true of preemptive scheduling? A) It requires a timer. B) A process keeps the CPU until it releases the CPU either by terminating or switching to waiting/blocked state. C) It incurs a cost associated with access to shared data. D) A process switches from the running state to the ready state when an interrupt occurs.

B is more common in case it is waiting for I/O to complete. D also has sense (relinguishing CPU forcibly because of a timer interrupt)

What is the problem with this code? _______ #include<stdio.h> int main() { int *p = (int *)malloc(sizeof(int)); p = NULL; free(p); } ________ A) Compiler Error: free can't be applied on NULL pointer B) Memory Leak C) Dangling Pointer D) The program may crash as free() is called for NULL pointer.

B) Memory Leak ______ B free() can be called for NULL pointer, so no problem with free function call. The problem is memory leak, p is allocated some memory which is not freed, but the pointer is assigned as NULL. The correct sequence should be following: free(p); p = NULL;

____ is how long it took for a process from the time of submission to produce the first response. A) CPU utilization B) Response time C) Turnaround time D) Throughput

B) Response time

This program will allocate the memory of ___ bytes for pointer "ptr". #include<stdio.h> #include<stdlib.h> int main() { int *ptr; ptr = (int*)malloc(sizeof(int)*4); ptr = realloc(ptr,sizeof(int)*2); return 0; } _________ A)2 B)4 C)8 D)none of the mentioned

C 8

What is the output of this program? #include<stdio.h> #include<stdlib.h> ________ int main() { int *ptr; *ptr = 10; *ptr = 20; printf("%d\n",*ptr); return 0; } _______ A)10 B)20 C)Segmentation fault D)None of the above

C The segmentation fault occurs because memory for the pointer has not been allocated in this program.

What is the output of this program? #include<stdio.h> #include<stdlib.h> int main() { int *ptr; ptr = (int *)malloc(sizeof(int)); printf("%d\n",*ptr); return 0; } _______ A)4 B)-1 C)undefined D)none of the mentioned

C undefined https://www.sanfoundry.com/tricky-buggy-questions-answers-malloc-free/

The ____ scheduling algorithm is more suitable for time-sharing systems. A) SJF B) FCFS (FIFO) C) RR D) STCF

C) RR

____ is how long it took to execute a process from the time of submission to completion. A) CPU utilization B) Response time C) Turnaround time D) Throughput

C) Turnaround time

Consider the following program. Where are i, j, k stored in memory? ____________ int i; int main() { int j; int *k = (int *)malloc(sizeof(int)); } ________ A) i, j and *k are stored in stack segment B) i and j are stored in stack segment. *k is stored on heap. C) i is stored in uninitialized part of data segment, j, k are stored in stack segment. *k is stored on heap. D) j is stored in uninitialized part of data segment, i is stored in stack segment. *k is stored on heap.

C) i is stored in uninitialized part of data segment, j, k are stored in stack segment. *k is stored on heap.

Consider the following program. Where are i, j, k stored in memory? ______________ int i; int main() { int j; int *k = (int *) malloc(sizeof(int)); } A) i, j and *k are stored in stack segment B) i and j are stored in stack segment. *k is stored on heap. C) i is stored in uninitialized part of data segment, j, k are stored in stack segment. *k is stored on heap. D) j is stored in uninitialized part of data segment, i is stored in stack segment. *k is stored on heap.

C) i is stored in uninitialized part of data segment, j, k are stored in stack segment. *k is stored on heap.

Consider the following three C functions: _____ [PI] int * g (void) { int x= 10; return (&x); } _____ [P2] int * g (void) { int * px; *px= 10; return px; } _______ [P3] int *g (void) { int *px; px = (int *) malloc (sizeof(int)); *px= 10; return px; } _______ Which of the above three functions are likely to cause problems with pointers? A)Only P3 B)Only P1 and P3 C)Only P1 and P2 D)P1, P2 and P3

C)Only P1 and P2 C In P1, pointer variable x is a local variable to g(), and g() returns pointer to this variable. x may vanish after g() has returned as x exists on stack. So, &x may become invalid. In P2, pointer variable px is being assigned a value without allocating memory to it. P3 works perfectly fine. Memory is allocated to pointer variable px using malloc(). So, px exists on heap, it's existence will remain in memory even after return of g() as it is on heap.

What is the output of this program? #include<stdio.h> #include<stdlib.h> int main() { int ret; int *ptr; ptr = (int *)malloc(sizeof(int)*10); free(ptr); free(ptr); return 0; } _______ A)it will print nothing B)it will give segmentaion fault C)undefined behaviour D)none of the mentioned

C)undefined behaviour

What does the code do? A)Prints out the signal number B)Assigns a handler for many signals C)Awaits for the user to send a signal D) All of the above #include <stdio.h> #include <assert.h> #include <signal.h> static void myHandler(int iSig) { printf("In myHandler with argument %d\n", iSig); } int main(void) { void (*pfRet)(int); pfRet = signal(SIGHUP, myHandler); /* 1 */ pfRet = signal(SIGINT, myHandler); /* 2 */ pfRet = signal(SIGQUIT, myHandler); /* 3 */ pfRet = signal(SIGILL, myHandler); /* 4 */ pfRet = signal(SIGTRAP, myHandler); /* 5 */ pfRet = signal(SIGABRT, myHandler); /* 6 */ pfRet = signal(SIGBUS, myHandler); /* 7 */ pfRet = signal(SIGFPE, myHandler); /* 8 */ pfRet = signal(SIGKILL, myHandler); /* 9 */ printf("Entering an infinite loop\n"); for (;;); return 0; }

D) All of the above

What does the code do? A)Prints out the signal number B)Assigns a handler for Ctrl+C (SIGINT) signal C)Awaits for the user to send a signal D) All of the above #include <stdio.h> #include <sys/wait.h> #include <assert.h> static void myHandler(int iSig) { printf("In myHandler with argument %d\n", iSig); } int main(void) { void (*pfRet) (int); pfRet = signal(SIGINT, myHandler); assert(pfRet != SIG_ERR); printf("Entering an infinite loop\n"); for(;;) { ; } return 0; }

D) All of the above #define _GNU_SOURCE /* Use modern handling style */ #include <stdio.h> #include <assert.h> #include <signal.h>

Which of the following is true of compaction? A) It can be done at assembly, load, or execution time. B) It is used to solve the problem of internal fragmentation. C) It cannot shuffle memory contents. D) It is possible only if relocation is dynamic and done at execution time.

D) It is possible only if relocation is dynamic and done at execution time.

Which languages necessarily need heap allocation in the run time environment? A) Those that support recursion B) Those that use dynamic scoping C) Those that use global variables D) Those that allow dynamic data structures

D) Those that allow dynamic data structures

____ is the number of processes that are completed per time unit. A) CPU utilization B) Response time C) Turnaround time D) Throughput

D) Throughput

What does the code do? A)It opens a new file temp.txt B)It cleans up the file if user presses Ctrl+C C)It raises a Ctrl+C signal D)All of the above ... static FILE *psFile; /* Must be global. */ static void cleanup(int iSig) { fclose(psFile); remove("tmp.txt"); exit(EXIT_FAILURE); } int main(void) { void (*pfRet)(int); psFile = fopen("temp.txt", "w"); pfRet = signal(SIGINT, cleanup); ... raise(SIGINT); return 0; /* Never get here. */ }

D) all of the above

What is the output of this program? #include<stdio.h> #include<stdlib.h> ______ int main() { int *ptr1, *ptr2; ptr1 = (int *) malloc(4); *ptr1 = 10; *ptr2 = free(ptr1); printf("%d\n",*ptr2); return 0; } _____ A)10 B)It will print the address in ptr1 C)It will print the address in ptr2 D)It will give an error

D)It will give an error ______ D The free() function returns no value

A fork system call will fail if A. The previously executed statement is also a fork call B. The limit on the maximum number of processes in the system would be exceeded. C. The limit on the maximum number of processes that can be under execution by a single user would be exceeded. D. Both (b) & (c)

D. Both (b) & (c)

A file is scattered into pieces across surface of a disk, when it is A.compressed B.archived C.defragmented D.fragmented

D.fragmented

Which of the following is/are true A) calloc() allocates the memory and also initializes the allocates memory to zero, while memory allocated using malloc() has random data. B) malloc() can be used to get the same effect as calloc(). C) calloc() takes two arguments, but malloc takes only 1 argument. D) Both malloc() and calloc() return 'void *' pointer. E) All of the above

E) All of the above

Splitting

Find free chunk of memory big enough to satisfy memory request and split it into two

Scheduler

Logic that decides which ready job to run

We use malloc and calloc for A) Dynamic memory allocation int S=100; int *a = (int *) malloc(S*sizeof(int)); B) Static memory allocation int[] a = int[100]; C) Both dynamic and static memory allocation D) None of the above

Look at example written on side of answer options: A) Dynamic memory allocation _____ A Both Calloc() and Malloc() are used for dynamic memory allocation. calloc() gives you a zero-initialized buffer, while malloc() leaves the memory uninitialized.

Benefits of memory virtualization

Memory utilization and efficiency ease of use in programming (pointer) Guarantee isolation for processes as well as OS

Merging

Merge smaller subsequent chunks into big chunks to return to user helps external fragmentation

FIFO scheduling

NONPREEMPTIVE send in order of arrival to queue bad if header packet is huge in comparison to the rest

2 approaches to switch between processes

Non-cooperative approach: os takes control cooperative approach: wait for system calls

non-cooperative approach:

Os takes control

RR vs FIFO

RR worse than FIFO when average turnaround time for equal job lengths is bad RR > FIFO: if jobs require fast response time, dont know run-time of each job, gives all jobs chance to run fast (esp the small mf)

Multi level feedback queue rules

Rule 1: If Priority(A) > Priority(B), A runs (B doesn't) Rule 2: If Priority(A) = Priority(B), A & B run in RR using the time slice of the queue Rule 3: When a job enters the system, it starts in the topmost queue (of the highest priority) Rule 4: Once a job uses up its time allotment (time slice s) at a given level (regardless of how many times it has given up the CPU), its priority is reduced (i.e., it moves down one queue) Rule 5: After some time period S, move all the jobs in the system to the topmost queue (to prevent starvation and S is larger than the default time slice s)

Round Robin (RR) scheduling

Run a job for a time slice ; then switch to the next job in the run queue until the jobs are finished.

Shorter time slice vs longer time slice

Shorter time: gives better response time cost of context switching dominate overall performance Longer time slice: gradually reduce cost of switching (like a loan) worse response time

EIP or Program Counter specifies the next instruction to execute. A) True B) False

True

Address Space

Virtual address space Os creates an abstraction of physical memory that consists of stack heap etc range of valid addresses in memory that are available for a program or process

A Cooperative Approach

Wait for system calls processes periodically give up cpu by making system calls such as yield

3 ways to time processes

Wall clock (real) time user cpu time system cpu time

Which of the following is true of multilevel feedback queue scheduling? A) Processes can move between queues. B) Each queue has its own scheduling algorithm. C) A queue cannot have absolute priority over lower-priority queues. D) It is the most general CPU-scheduling algorithm.

a) A) Processes can move between queues.

A (harware-generated) interrupt breaks the execution of instructions and diverts its execution to a) Interrupt handler routine b) Counter word register c) Execution unit d) control unit

a) Interrupt handler routine

Filenames in UNIX are case-sensitive. a) True b) False

a) True

Less privileged mode is often referred as A.User Mode B.Control Mode C.Kernel Mode D.System Mode

a) User Mode

In multilevel feedback scheduling algorithm ____________ a) a process can move to a different classified ready queue b) classification of ready queue is permanent c) processes are not classified into groups d) none of the mentioned

a) a process can move to a different classified ready queue

Physical memory is broken into fixed-sized blocks called ________ a) frames b) pages c) backing store d) none of the mentioned

a) frames

When we execute a C program, CPU runs in ____ mode. a) user b) kernel c) supervisory d) system

a) user

What is a buffer? a. A section of memory used as a temp staging area for input or output data. b. The cable that connects a data source to the bus. c. Any stream that deals with IO. d. A file that contains binary data.

a. A section of memory used as a temp staging area for input or output data.

_________ allocates the smallest hole (free fragment) available in the memory. a.Best Fit b.Worst Fit c.First Fit d.None of the above

a.Best Fit

Paging _________. a.prevents the external memory fragmentation problem b.allows modular programming c.allows structured programming d.avoids deadlock

a.prevents the external memory fragmentation problem

Internal Fragmentation

allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used

Switching the CPU to another Process requires to save state of the old process and loading new process state is called as __________. A. Process Blocking B. Context Switch C. Time Sharing D. None of the above

b) Context Switch

How can the software run protected functions in kernel mode? a) Sending signals to CPU through bus b) Executing a special operation called system call (trap) c) Executing a special program called system program d) Executing a special program called interrupt trigger program

b) Executing a special operation called system call (trap)

In the layered approach of Operating Systems __________ a) Bottom Layer(0) is the User interface b) Highest Layer(N) is the User interface c) Bottom Layer(N) is the hardware d) Highest Layer(N) is the hardware

b) Highest Layer(N) is the User interface

In ____ mode, the kernel runs on behalf of the user. a) user b) kernel c) real d) all

b) Kernal

With paging there is no ________ fragmentation. a) internal b) external c) either type of d) none of the mentioned

b) external

The __________ is used as an index into the page table. a) frame bit b) page number c) page offset d) frame offset

b) page number

Every address generated by the CPU is divided into two parts. They are ____________ a) frame bit & page number b) page number & page offset c) page offset & frame bit d) frame offset & page offset

b) page number & page offset

Logical memory is broken into blocks of the same size called _________ a) frames b) pages c) backing store d) none of the mentioned

b) pages

The size of a page is typically ____________ a) varied b) power of 2 c) power of 4 d) none of the mentioned

b) power of 2

_________ allocates the largest hole (free fragment) available in the memory. a.Best Fit b.Worst Fit c.First Fit d.None of the above

b.Worst Fit

What statement concerning privileged instructions is considered false? A) They may cause harm to the system. B) They can only be executed in kernel mode. C) They cannot be attempted from user mode. D) They are used to manage interrupts.

c) They cannot be attempted from user mode

The operating system maintains a ______ table that keeps track of how many frames have been allocated, how many are there, and how many are available. a) page b) mapping c) frame d) memory

c) frame

The _____ table contains the base address of each page in physical memory. a) process b) memory c) page d) frame

c) page

Header of malloc chunk

contains size of malloc and magic number for integrity checking

If the size of virtual(logical) address space is 2 to the power of m, and a page size is 2 to the power of n addressing units, then the high order _____ bits of a virtual(logical) address designate the page number, and the ____ low order bits designate the page offset. a) m, n b) n, m c) m - n, m d) m - n, n

d) m - n, n

Process are classified into different groups in ____________ a) shortest job scheduling algorithm b) round robin scheduling algorithm c) priority scheduling algorithm d) multilevel feedback queue scheduling algorithm

d) multilevel feedback queue scheduling algorithm

Which of the following memory allocation scheme suffers from External fragmentation? a.Best-fit b.Worst-fit c.First-fit d.All of the above

d.All of the above D Mostly best-fit, though suffers

The problem of fragmentation arises in ________. a.Static storage allocation b.Stack allocation storage c.Stack allocation with dynamic binding d.Heap allocation

d.Heap allocation

Division of a hard disk into separate areas of data is called a.Clustering b.Formatting c.Sectioning d.Fragmenting e.Partitioning

e.Partitioning

niceness value

how "nice" a process is to other processes same nice value: 50%/50% between cpu time of parent and children

1,000,000,000 bytes i. Gigabyte ii. Kilobytes iii. Megabyte iv. Terabyte

i. Gigabyte

Metric

measurement of scheduling quality

For every process there is a __________ a) page table b) copy of page table c) pointer to page table d) all of the mentioned

page table and pointer to page table

Workload

set of job description

Preemption

temporarily interrupt a task with intention to continue the task later

A ____ can be used to prevent a user program from never returning control to the operating system. A) portal B) program counter C) firewall D)timer

timer

External Fragmentation

total memory space exists to satisfy a request, but it is not contiguous small bits of unallocated memory that is too small to be used, hence becomes useless


Conjuntos de estudio relacionados

Simulation Lab 2.2: Module 02 Install and Use Wireshark

View Set