When we execute a C program, CPU runs in ____ mode. a) user b) kernel c) supervisory d) system
a) user
In ____ mode, the kernel runs on behalf of the user. a) user b) kernel c) real d) all
b) Kernal
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
Less privileged mode is often referred as A.User Mode B.Control Mode C.Kernel Mode D.System Mode
a) User Mode
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
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)
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
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.
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)
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.
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.
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.
Let the default action occur. For a divide-by-zero condition, the default is to terminate the process.
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 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
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
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.
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.
Let the default action occur. For a divide-by-zero condition, the default is to terminate the process.
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.
D) All of the above
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
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
A) Specifies a handler for SIGINT signal
____ is the number of processes that are completed per time unit. A) CPU utilization B) Response time C) Turnaround time D) Throughput
D) Throughput
____ 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
____ 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
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)
The ____ scheduling algorithm is more suitable for time-sharing systems. A) SJF B) FCFS (FIFO) C) RR D) STCF
C) RR
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 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.
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
How many read/write heads are there per platter? a.1 b.2 c.3 d.4
2 b
The "geometry" specification of a drive consists of a. Tracks b. Heads c. Sectors/track d. Cylinders e. Total sectors
b, c, and d
b. Heads c. Sectors/track d. Cylinders https://www.brainbell.com/tutors/A+/Hardware/_Geometry.htm
●Head: If a hard disk drive has four platters, it can have up to eight heads. ●Sectors are like pie slices. Each arc is a sector and holds 512 bytes of data. ●Data is stored in circular paths on the surface of each head.
Sectors are typically a.1.2 megabytes b.256 kilobytes c.512 bytes d.512 kilobytes e.1024 bytes
c.512 bytes
A file is scattered into pieces across surface of a disk, when it is A.compressed B.archived C.defragmented D.fragmented
D.fragmented
How often would you use a disk defragmenter? a.Twice a day b.Once a day c.Once a week d.Once a month
d.Once a month
Division of a hard disk into separate areas of data is called a.Clustering b.Formatting c.Sectioning d.Fragmenting e.Partitioning
e.Partitioning
Partition tables on a hard disk drive may contain: a. d and e b. Two primary partitions and two extended partitions c.Unlimited partitions d.Up to four primary partitions e.Three primary partitions and one extended partition
A: D e
d.Up to four primary partitions e.Three primary partitions and one extended partition
"Volumes" are a.Groups of cylinders b.Partitions c.Master boot records d.Usually assigned a unique identifier, such as a drive letter or folder e.Groups of folders
B d "Volumes" generally has several meanings
b. Partitions d. Usually assigned a unique identifier, such as a drive letter or folder
All primary partitions must have a.An operating system b.An entry in the partition table c.Logical drives d.A corresponding extended partition e.A unique identifier such as a drive letter or folder
b. An entry in the partition table and
e. A unique identifier such as a drive letter or folder
Partitioning a hard drive allows one to a.Increase disk space b.Install multiple operating systems on it c.Proceed with logical partitioning d.Share drive letters e.Encrypt files
b.Install multiple operating systems on it
and
c.Proceed with logical partitioning
Where is the boot sector located on a hard disk drive? a.First sector b.Second sector c.Last sector d.In the cache e.The file allocation table
a.First sector
The boot sector on a hdd contains a.The master boot record b.Speadsheets c.A copy of system BIOS d.Games e.The partition table
a.The master boot record
e.The partition table
The first sector of the hard drive is called a.The first partition b.Cylinder 0 c.The boot sector d.The partition table e.The stripe
c.The boot sector
The boot sector in a basic disk contains a.The master boot record and file allocation table b.The master boot record and partition table c.BIOS and file allocation table d.The partition table and file allocation table e.Boot.ini
b.The master boot record and partition table
Filenames in UNIX are case-sensitive. a) True b) False
a) True
The most common file type is ___ a) ordinary (data) file b) directory file c) device file d) ordinary file and directory file
A Explanation: The most common file type is an ordinary file or a regular file. It contains data as a stream of characters. Ordinary files are also of two types, text file and binary file.
What is a directory file? a) a directory containing data b) a directory containing details of the files and subdirectories it contains c) a directory contains files d) a directory containing data and files
B Explanation: A directory file contains no data but some details of the subdirectories and files that it contains. Directory files contain an entry for every file and subdirectory in it and each entry has some necessary information regarding files and subdirectories.
When we log in, the UNIX places us in a directory, called ______ directory a) home b) main c) parent d) current
a) home
The root directory in UNIX-like OSs is represented by ___ a) b) / c) * d) $
b) /
UNIX treats everything as a file. a) True b) False
A Explanation: All physical devices such as printers, hard disk are treated as files by the UNIX system. Even the kernel, shell and main memory is treated as a file by UNIX operating system.
UNIX imposes no rule for framing filename extensions - but software applications may impose rules (e.g. C compiler expects source code filenames to end with .c). a) True b) False
A Explanation: UNIX imposes no rules for framing filename extensions. For example, a shell script doesn't need to have the .sh implication, even though it helps in identification. In all cases, it's the application that imposes the restriction. For example, C compiler expects C program filenames to end with .c .
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.
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/
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.
Smallest addressable storage unit on hard disk, typically 512 bytes
FAT
bit
Sector
MBR
Sector
1,000,000,000 bytes i. Gigabyte ii. Kilobytes iii. Megabyte iv. Terabyte
i. Gigabyte
Independent organizational structure that allows the user to store and retrieve data
File System
Files
File Slack
File System Area
File System
Group of sectors 1.Sector 2.Acquire 3.File 4.Cluster
Answer: 4. Cluster
explanation: 2.Number of Sectors per cluster can range between 1 and 64 3.Sectors per cluster established when the volume is formatted 4.Windows will usually set 8 sectors per cluster which would give a cluster size of 4096
Are written at the cluster level 1.Files 2.Byte 3.Bit 4.FAT
Answer: 1. Files
explanation: 2.Two files can not be allocated to the same cluster at the same time3.If a file is larger than a single cluster it will use multiple clusters in the volume4.When using multiple clusters they may be contiguous or non-contiguous5.Often have a physical size and logical size
A hard drive has 1 sector (512 bytes) per cluster, and we know that the data area begins in sector 33. Suppose a certain file begins in cluster number 5. Which disk sector contains the beginning of the file? A)38 B)33 C)5 D)0
A)38
A certain hard drive has 4 KB per cluster, and we know that the data area begins in sector 100. If a particular file begins in cluster 10, which disk sectors are used by the cluster? A)180-187 B)180-183 C)100-107 D)110-117
A)180-187
This is a table that contains information about the clusters that are set up by the file system. Acts as a roadmap for the operation system to find all of the clusters in a file i. File Name Area ii. File to File iii. File Allocation Table iv. File System Area
iii. File Allocation Table
Collection of addressable sectors that an Operating System or application can use for that data storage 1.Nibble 2.Volume 3.Files 4.byte
Answer 2.Volume
explain: 1.Hard disk is a volumeMultiple smaller volumes can be combined o create a larger volume
With the Windows FAT filesystem, a larger cluster size means
less internal fragmentation
larger disk partitions can be handled
less external fragmentation
more disk I/O operations per cluster
none of the above
Answer: 3, 4 3. less external fragmentation 4. more disk I/O operations per cluster
explanation: External fragmentation also occurs in file systems as many files of different sizes are created, change size, and are deleted. The effect is even worse if a file which is divided into many small pieces is deleted, because this leaves similarly small regions of free spaces. https://en.wikipedia.org/wiki/Fragmentation_(computing)
●Both 3 and 4 make sense, so I checked them both on the slide.When you have smaller cluster size, it means files will be in many small pieces scattered all over the diskand as you delete files there will be more small clusters (blocks) that are free for use. Thus more external fragmentation.Larger cluster size -> less external fragmentationThe larger cluster size also means more disk I/O since there are more sectors to move between disk and memory.Larger cluster size -> more internal fragmentation because a file with a small size (e.g. just 1 byte) will still take a complete cluster (block), effectively wasting a lot of storage space.
Hard links and symbolic links are the same a) TRUE b) FALSE
B: Symlinks have diff inodenum, hardlinks have same inodenum. If remove orig file symlinks broken, hardlinks not broken due to link_count. Symlinks can be to directories, hardlinks only to regular files. Symlinks can traverse partitions, hardlinks only to the same partition (inodenums are specific to a part)
How to make a filesystem?
🞐After you partition a hard disk, use mkfs tool to make a file system 🞐Write an empty file system, starting with a root directory, on to a disk partition. ⬥Input: 🞆A device (such as a disk partition, e.g., /dev/sda1) 🞆A file system type (e.g., ext3) prompt> mkfs -t ext3 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux prompt> file -sL /dev/sdb1 /dev/sdb1: Linux rev 1.0 ext3 filesystem data (large files)
How to Mount a file system?
🞐mount() ⬥Take an existing directory as a target mount point. ⬥Paste a new file system onto the directory tree at that point. ⬥Examples: prompt> sudo mount /dev/sdd1 /media/usb
prompt> sudo mount /dev/sdb1 /mnt/media 🞆The pathname /media/usb and /mnt/media/ now refer to the roots of the newly-mounted directories.
The directory /media is the a) mount point for removable media b) mount point for filesystem c) mount point for removable media & filesystem d) none of the mentioned
a) mount point for removable media
512
What does it show? a.Total and free memory b.Number of running processes c.Hard Disk Sector size d.Number of open files
c.Hard Disk Sector size
Everything is a file in UNIX C
MemTotal: .... MemFree: .... What does it show? a.Total and free memory b.Number of running processes c.Hard Disk Sector size d.Number of open files
a.Total and free memory
Everything is a file in UNIX A
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
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.
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.
We use malloc and calloc for A) Dynamic memory allocation int S=100; int *a = (int ) malloc(Ssizeof(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.
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.
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;
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
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.
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.
C The segmentation fault occurs because memory for the pointer has not been allocated in this program.
D)It will give an error ______ D The free() function returns no value
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;
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).
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
A)0
C 8
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.
C)undefined behaviour
C undefined
https://www.sanfoundry.com/tricky-buggy-questions-answers-malloc-free/
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.
_________ 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
_________ 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
_____ 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
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
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
With paging there is no ________ fragmentation. a) internal b) external c) either type of d) none of the mentioned
b) external
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
Physical memory is broken into fixed-sized blocks called ________ a) frames b) pages c) backing store d) none of the mentioned
a) frames
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
The _____ table contains the base address of each page in physical memory. a) process b) memory c) page d) frame
c) page
For every process there is a __________ a) page table b) copy of page table c) pointer to page table d) all of the mentioned
a) page table
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