1/140
Looks like no tags are added yet.
A Process Control Block (PCB) ___.
A) includes information on the process’ state.
B) stores the address of the next instruction to be processed by a different process.
C) determines which process is to be executed next.
D) is an example of a process queue.
A - The PCB tracks what is stored about a process and is necessary to save information between context switches.
What is the ready state of a process?
A) when process is ready to be schedled to run.
B) when a process is waiting to run until after another process’ execution has completed.
C) when process is using the CPU.
D) when the process result is ready.
A - Ready state means a process is ready to acquire the CPU. When the process is unable to run until some task has been completed, the process is in blocked state. If the process is using the CPU, it is in running state.
The list of processes waiting for a particular I/O device is called a(n) ___.
A) waiting queue
B) device queue
C) ready queue
D) interrupt queue
E) A or B
E - Either a waiting queue (because they are waiting) or a device queue (because they are on a particular device).
A process that has terminated, but whose parent has not yet called wait(), is known as a ___ process.
A) zombie
B) orphan
C) terminated
D) init
A
The ___ process is assigned as the parent to orphan processes.
A) zombie
B) init (PID 1)
C) main
D) renderer
B
A fork system call could 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) Either (B) or (C).
D
The ___ refers to the max number of processes in memory.
A) process count
B) long-term scheduler
C) degree of multiprogramming
D) CPU scheduler
C - A makes sense too. The degree of multiprogramming describes the maximum number of processes that a single-processor system can accommodate efficiently. The primary factor affecting the degree of multiprogramming is the amount of memory available to be allocated to executing processes.
How does the OS kernel communicate to an application process?
A) Signals
B) Bus
C) Hardware interrupts
D) Ethernet
A

A

A

D

D

A

D
A process may transition to the ready state by which of the following events?
A) Completion of a blocking I/O event.
B) Awaiting its turn on the CPU.
C) Newly-admitted process.
D) All of the above.
D
A __ saves the state of the currently running process and restores the state of the next process to run.
A) save-and-restore
B) state switch
C) context switch
D) none of the above
C - Context switch refers to switch between processes.
___ 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 - Total competition-arrival time in wallclock terms.
___ is how long it took for a process from the time to submission to produce the first response.
A) CPU utilization
B) response time
C) turnaround time
D) throughput
B - Response time is helpful for interactive jobs where you want it to give signs quickly.
The ___ scheduling algorithm is more suitable for multi-user time-sharing systems.
A) SJF
B) FCFS (FIFO)
C) RR
D) STCF
C - So that you don’t have users waiting too long. RR is for jobs where you demand interactivity, like gaming, browser, and Zoom.
___ is what portion of the clock cycles the CPU is actually doing computations vs. sitting idle for I/O to finish.
A) CPU utilization
B) response time
C) turnaround time
D) throughput
A
___ is the number of processes that are completed per time unit.
A) CPU utilization
B) response time
C) turnaround time
D) throughput
D - Throughput might be a more helpful metric if you have a FIFO scheduler, since FIFO assumes all jobs start at the same time and have the same duration. Schedulers are simple, so throughput would be more helpful as a metric to also factor in the speed of your system.
The PID of the kernel scheduler process is generally:
A) Undefined
B) 0
C) 1
D) 3
B
Which 3 of the following are true of preemptive scheduling?
A) It requires a timer interrupt.
B) A process keeps the CPU until it releases the CPU either by terminating or switching to ready/blocked state.
C) It incurs a cost associated with access to shared data.
D) A process may switch from the running state to the ready state when a time slice elapses/timer interrupt occurs.
E) A, B, D.
E - B is more common in case it is waiting for I/O to complete. D also makes sense (relinquishing CPU forcibly because of a timer interrupt).
Processes are classified into different groups and can move between groups in ___.
A) shortest job scheduling algorithm
B) round robin scheduling algorithm
C) priority scheduling algorithm
D) multilevel feedback queue (MLFQ) scheduling algorithm
D - Though, C, as well, uses a priority queue. In MLFQ, the processes can change between the queues (groups), while in priority scheduling they have a fixed priority - that’s the difference. Priority scheduling algorithm: the jobs have a priority which doesn’t change, different from MLFQ where they can move between queues.
A ___ can be used to prevent a user program from never returning control to the operating system (OS).
A) portal
B) program counter
C) firewall
D) timer interrupt
D
A time slice (OS defined) is a multiple of a timer interrupt interval (HW/CPU defined).
A) True
B) False
A - The hardware generated timer interrupt is used by each OS to specify a time slice as a multiple.
In multilevel feedback scheduling algorithm ___.
A) a process can move to a different queue
B) classification in a queue is permanent
C) a queue never contains more than one process
D) a job is always in a running state
A - Queues are not permanent.
Does the parent in your Assignment 2 have a higher priority than its children?
A) Yes
B) No
B
Which of the following is true of multilevel feedback queue scheduling?
A) Processes can move between queues.
B) Each queue can have its own scheduling algorithm.
C) A queue cannot have absolute priority over lower-priority queues.
D) It is the most general CPU-scheduling algorithm.
E) A and B
E - Each queue has a scheduling algorithm and processes move between queues.
Extended Instruction Pointer (EIP) / Program Counter (PC) specifies the address of the next instruction to execute.
A) True
B) False
A
Which languages need to support heap allocation in the run time environment?
A) Those that support recursive function calling.
B) Those that use dynamic scoping.
C) Those that use global variables.
D) Those that allow dynamic data structures.
D
We use malloc and calloc for:
A) dynamic memory allocation
B) static memory allocation
C) both dynamic and static memory allocation
D) constant 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 unitialized.
What is the return type of malloc() and calloc()?
A) void *
B) pointer of allocated memory type
C) void **
D) int *
A - malloc() and calloc() return void *. You may get a warning in C if you don’t type cast the return type to appropriate 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 the following:
free(p);
p = NULL;

C

C - The segmentation fault may occur because memory for the pointer has not been allocated in this program. If you are lucky is might work, depending on what garbage value ptr has.

D - The free() function returns no value.

C - Undefined because the mem is not initialized.

A

B

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).

D - 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).
How many bytes are in a char?
A) 1
B) 2
C) 3
D) 4
A - char just means a byte of data and is not an actual encoding.
Which of the following is/are true?
A) calloc() allocates memory and also initializes the allocated memory to zero, while memory allocated with malloc() is expected to have random data.
B) malloc() and an extra init (zero out) operation can still be used to get the same effect as calloc().
C) calloc() takes two arguments, but malloc only takes one argument (number of bytes).
D) Both malloc() and calloc() return void * pointer.
E) All of the above.
E

A - calloc makes memory zero.

D - int is 4 bytes long. Second allocation is 4 bytes * 8 = 32 bytes.

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.

C - undefined error.
C is:
A) pass by value
B) pass by reference
A - C is pass by value, but it simulates pass by reference.
The problem of ___ fragmentation arising in Heap (dynamic) allocation means ___.
A) external fragmentation / memory going unused between allocated blocks
B) internal fragmentation / memory going unused inside allocated blocks
C) external fragmentation / memory going unused inside allocated blocks
D) internal fragmentation / memory going unused between allocated blocks
E) A and B are correct
E
___ 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
___ 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
___ is the dynamic storage-allocation algorithm which results in the smallest leftover hole (free memory leftover block) in memory.
A) first fit
B) best fit
C) worst fit
D) none of the above
B
Which of the following memory allocation scheme suffers from any external fragmentation?
A) best fit
B) worst fit
C) first fit
D) all of these suffer in different situations
D - Though, mostly best fit suffers.
Paging is a memory-management scheme that permits a process’ physical address space (in hardware RAM) to be noncontiguous.
A) True
B) False
A
Paging prevents ___ fragmentation.
A) internal
B) external
C) either type of
D) none of the mentioned
B - Paging is compatible with the free-space memory management via a linked list that we saw previously, but think of all blocks (pages) as having the same size. Thus you avoid external fragmentation. The idea behind virtual memory paging is that memory is divided into fixed size pages.
In paging, the logical memory (virtual address space) is broken into blocks of the same size called ___.
A) frames
B) pages
C) backing store
D) none of the mentioned
B - Pages pertain to the virtual address space.
In paging, physical memory (RAM) is broken into fixed-size blocks called ___.
A) frames
B) pages
C) backing store
D) none of the mentioned
A - Frames pertain to RAM, physical memory.
Every virtual address generated by the CPU (PC register) is divided into two parts. They are ___.
A) frame bit and page number
B) page number and page offset
C) page offset and frame bit
D) frame offset and page offset
B
The ___ table at index p contains the base address f of the corresponding frame in physical memory (RAM).
A) process
B) memory
C) page
D) frame
C
The ___ is used as an index into the page table.
A) frame bit
B) page number
C) page offset
D) frame offset
B
The size of a page is typically ___.
A) varied
B) power of 2
C) power of 4
D) none of the mentioned
B
If you know that your page size is 4096 on your system, then which operation on a memory address would for sure send you to the next (following) page in memory?
A) address += 220
B) address += 212
C) address >> 20
D) address >> 12
B
For every running process there is a ___.
A) page table
B) copy of page table
C) pointer to page table
D) all of the mentioned
E) A and C
E - Each process has a page table and there is a pointer to access it for efficiency.
The OS kernel maintains one ___ table that keeps track of how many frames have been allocated, how many there are, and how many are available.
A) page
B) mapping
C) frame
D) memory
C
If the size of the 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
Page tables are kept in main memory and a ___ points to the current page table.
A) page table base register (PTBR)
B) page table base pointer
C) page table register pointer
D) page table base
A
Paging increases the ___ time.
A) I/O (because of disk swapping, using the disk as extension of physical RAM)
B) execution (for every virtual address you need to do address translation)
C) context-switch (switching from one page table to another)
D) all of the mentioned
D
Paging reduces external fragmentation and the need for compaction, two problems that plague contiguous memory allocation.
A) True
B) False
A
In Unix, the pipe(int filedesc[2]) call returns:
A) 1 if successful, 0 on error
B) 0 if successful, -1 on error
C) A pair of sockets always connected across machines
D) The PID of the child process
B
In a pipe, which file descriptor is used for reading?
A) fd[0]
B) fd[1]
C) Both ends can read/write interchangeably
D) Depends on fork() call
A
A pipe is typically:
A) Bi-directional
B) Uni-directional
C) Multi-directional
D) Full-duplex by default
B
Where does the operating system maintain the buffer for a pipe?
A) User space
B) Kernel space
C) File system cache
D) Virtual memory only
B
What does the mmap() system call return on success?
A) File descriptor
B) Starting address of the mapped region
C) Process ID
D) Buffer size in bytes
B
Which flag allows multiple processes to see updates when using mmap?
A) MAP_ANONYMOUS
B) MAP_PRIVATE
C) MAP_SHARED
D) MAP_RDWR
C
Which function explicitly synchronizes memory-mapped regions to disk?
A) sync()
B) munmap()
C) msync()
D) fflush()
C
In Unix, after calling:
int fd[2];
pipe(fd);
the system returns two file descriptors. If fd[0] = 3, what is the most likely value of fd[1]?
A) 0
B) 1
C) 4
D) It depends on the OS, could be any random value
C
Why should each process close the pipe end it won't use after fork()?
A) To save file descriptor quota
B) To prevent the reader from blocking forever waiting for EOF (End-of-file) that never comes
C) Because the OS requires it before calling exec()
D) To allow both processes to write at the same time
B
Which sequence of calls in shell.c correctly processes multiple files in parallel for A2?
A) fork(); wait(); fork(); wait(); — one at a time
B) Fork all children first, then call wait() in a loop
C) exec() all files from the parent process
D) fork() once and pass all filenames to the child
B
Why does A2 recommend execvp() over other exec variants?
A) It is faster than all other variants
B) It does not replace the process image
C) It searches PATH and accepts a flexible null-terminated argv-style array
D) It automatically forks before executing
C
When the pipe buffer (64 KB) is completely full, what happens to a process that calls write() on the write end?
A) write() returns an error immediately
B) The data is silently truncated
C) write() blocks until the reader consumes enough space
D) The OS automatically expands the buffer
C
After pipe() and fork(), both parent and child hold both ends of the pipe. What could go wrong if neither closes their unused end?
A) The pipe buffer doubles in size
B) Both can write simultaneously, corrupting data
C) Deadlock — if the parent reads and the child also reads and blocks, the parent waits forever for the child to write
D) The child inherits the parent's file descriptors incorrectly
C
char *args[] = {"ls", ".", NULL};
execvp(args[0], args);
What does this do?
A) Lists parent directory
B) Lists current directory
C) Prints error
D) Does nothing
B
You want to redirect the pipe's read end so the child process reads from it as if it were stdin. Which call achieves this?
A) dup2(fd[1], STDIN_FILENO)
B) dup2(STDIN_FILENO, fd[0])
C) dup2(fd[0], STDIN_FILENO)
D) dup2(fd[0], fd[1])
C
What is wrong with this code?
int fd[2];
pipe(fd);
pid_t pid = fork();
if (pid == 0) {
write(fd[1], "hello", 5);
} else {
read(fd[0], buf, 5);
wait(NULL);
}
A) fork() should be called before pipe()
B) Neither process closes its unused pipe end, which can cause the reader to never get EOF
C) write() and read() have the wrong file descriptors
D) Nothing is wrong with this code
B
What does this code print?
int fd[2];
pipe(fd);
pid_t pid = fork();
if (pid == 0) {
close(fd[1]);
char buf[10];
int n = read(fd[0], buf, 10);
printf("child read %d bytes\n", n);
exit(0);
} else {
close(fd[1]);
wait(NULL);
}
A) child read 0 bytes
B) child read 10 bytes
C) The child blocks forever on read()
D) None of the above
A
Which of the following best describes how signals are mediated?
A) Directly by hardware
B) By user applications
C) By the OS kernel
D) By network protocols
C
When a signal is received by a process, what happens?
A) The process continues without interruption
B) The process is terminated immediately
C) The OS kernel stops the process, executes the signal handler, then resumes the process
D) The signal is stored for later processing
C
Which command sends SIGKILL to a process?
A) kill pid
B) kill -9 pid
C) kill -2 pid
D) kill -15 pid
B
What system call allows a process to send a signal to itself?
A) kill()
B) raise()
C) signal()
D) sigaction()
B
What signal is sent when a user presses Ctrl-C?
A) SIGTERM
B) SIGINT
C) SIGKILL
D) SIGQUIT
B
When will this running program terminate?
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void sig_handler(int signo)
{
printf("Caught signal %d\n", signo);
}
int main(void)
{
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
while(1)
sleep(1);
return 0;
}
A) When you press Ctrl-C
B) When you do "kill processid" (sends SIGTERM by default)
C) When you do "kill -9 processid" (sends SIGKILL)
D) Any of the above
C
What output will you see if you run this program and execute "kill -2 processid"?
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void handler1(int signo)
{
printf("Handler 1: signal %d\n", signo);
}
void handler2(int signo)
{
printf("Handler 2: signal %d\n", signo);
}
int main(void)
{
signal(SIGINT, handler1);
signal(SIGUSR1, handler2);
while(1)
sleep(1);
return 0;
}
A) Handler 1: signal 2
B) Handler 2: signal 2
C) Both handlers are called
D) No output, program terminates
A
What happens when you send SIGKILL to this program?
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void sig_handler(int signo)
{
printf("Caught signal %d, cleaning up...\n", signo);
}
int main(void)
{
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
signal(SIGKILL, sig_handler); // Attempting to catch SIGKILL
while(1)
sleep(1);
return 0;
}
A) "Caught signal 9, cleaning up..." is printed
B) The program ignores SIGKILL
C) The program terminates immediately without calling the handler
D) signal() returns an error for SIGKILL
C
What will this program print?
#include <stdio.h>
#include <string.h>
int main() {
char str[] = {'H','e','l','l','o'};
printf("%d\n", strlen(str));
return 0;
}
A) 5
B) 6
C) Undefined behavior
D) 0
C
What block executes if a child process calls exit(0)?
if (WIFEXITED(status)) {
printf("Normal exit\n");
} else if (WIFSIGNALED(status)) {
printf("Killed by signal\n");
}
A) Both blocks
B) The first if block
C) The second else if block
D) Neither
B
Which of the following sends an EOF to a program?
A) Ctrl-C
B) Ctrl-Z
C) Ctrl-D
D) kill -9
C
Which function can automatically resize the buffer if the input is longer than expected?
A) fgets()
B) getline()
C) Both
D) Neither
B
A _________________ saves the state of the currently running process and restores the state of the next process to run.
A) save-and-restore
B) state switch
C) context switch
D) none of the above
C
____ 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