Matoshri College of Engineering & R. C. Nashik Department of Computer Engineering. Subject :- OPERATING SYSTEM DESIGN. Semester:- 5 Subject I/c :- Mr. Ranjit Gawande. MODEL ANSWER – FOR NOV DEC 14

Model Ans. Paper for Operating System Design 2012 Pat. Q1.A Explain in short - BIOS, MBR and init( ) process. Ans.

[6]

The stages involved in Linux Booting Process are: 1) BIOS 2) Boot Loader 3) MBR 4) GRUB 5) Kernel 6) Init 7) Runlevel scripts The details of BIOS as below. This is the first thing which loads once power on machine. Pressing the power button of the machine, CPU looks out into ROM for further instruction. a) The ROM contains JUMP function in the form of instruction which tells the CPU to bring up the BIOS b) BIOS determines all the list of bootable devices available in the system. c) Prompts to select bootable device which can be Hard Disk, CD/DVD-ROM, Floppy Drive, USB Flash Memory Stick etc (optional) d) Operating System tries to boot from Hard Disk where the MBR contains primary boot loader. Boot Loader This phase includes loading of the boot loader (MBR and GRUB/LILO) into memory to bring up the kernel. MBR (Master Boot Record) a)It is the first sector of the Hard Disk with a size of 512 bytes. b)The first 434 - 446 bytes are the primary boot loader, 64 bytes for partition table and 6 bytes for MBR validation timestamp. MBR directly cannot load the kernel as it is unaware of the filesystem concept and requires a boot loader with file system driver for each supported file systems, so that they can be understood and accessed by the boot loader itself. To overcome this situation GRUB is used with the details of the filesystem in /boot/grub.conf and file system drivers GRUB (GRand Unified Boot loader) This loads the kernel in 3 stages 1) GRUB stage 1 2) Stage 1.5 3) Stage 2 The primary boot loader takes up less than 512 bytes of disk space in the MBR - too small a space to contain the instructions necessary to load a complex operating system. Instead the primary boot loader performs the function of loading either the stage 1.5 or stage 2 boot loader.

Q1.B What is kernel? What facility kernel should provide? Ans.

A "Kernel" is the central component of a system. The Kernel is the core of the system; it provides the very basic facilities for the management of efficient execution of the system. In an operating system,Kernel provides the most basic interface to the system hardware and resources. It also provides the most basic management facilities, such as processor management, I/O management, memory management, and process management. A kernel can be contrasted with a shell, the outermost part of an operating system that

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 1

[4]

interacts with user commands. Kernel and shell are terms used more frequently in Unix operating systems

The kernel performs various primitive operations on behalf of user processes to support the user interface. The services provided by the kernel are 1) Controlling the execution of processes by allowing their creation, termination or suspension, and communication . 2) Scheduling processes fairly for execution on the CPU. Processes share the CPU in a time-shared manner: the CPU5 executes a process, the kernel suspends it when its time quantum elapses, and the kernel schedules another process to execute. The kernel later reschedules the suspended process. 3) Allocating main memory for an executing process. The kernel allows processes to share portions of their address space under certain conditions, but protects the private address space of a process from outside tampering. If the system runs low on free memory, the kernel frees memory by writing a process temporarily to secondary memory, called a swap device. If the kernel writes entire processes to a swap device, the implementation of the UNIX system 1s called a swapping system; if it writes pages or memory to a swap device, it is called a paging system. 4) Allocating secondary memory for efficient storage and retrieval of user data. This service constitutes the file system. The kernel allocates secondary storage for user files, reclaims unused storage, structures the file system in a well understood manner, and protects user files from illegal access. 5) Allowing processes controlled access to peripheral devices such as terminals, tape drives, disk drives, and network·devices. OR Q2A

What are different multi-threading models?

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 2

[6]

Ans.

The use of a multicore system to support a single application with multiple threads, such as might occur on a workstation, a video-game console, or a personal computer running a processor-intense application, raises issues of performance and application design. In this section, we first look at some of the performance implications of a multithreaded application on a multicore system and then describe a specific example of an application designed to exploit multicore capabilities.

Multiple threads within the same application can run in parallel on multiple processors, and a blocking system call need not block the entire process. If properly designed, this approach should combine the advantages of the pure ULT (user level thred) and KLT (Kernel level thread ) approaches while minimizing the disadvantages.

Multi-threading Models Some operating system provide a combined user level thread and Kernel level thread facility. Solaris is a good example of this combined approach. In a combined system, multiple threads within the same application can run in parallel on multiple processors and a blocking system call need not block the entire process. Multi-threading models are three types Many to many relationship. Many to one relationship. One to one relationship. Many to Many Model The many-to-many model multiplexes any number of user threads onto an equal or smaller number of kernel threads. The following diagram shows the many-to-many threading model where 6 user level threads are multiplexing with 6 kernel level threads. In this model, developers can create as many user threads as necessary and the corresponding Kernel threads can run in parallel on a multiprocessor machine. This model provides the best accuracy on concurrency and when a thread performs a blocking system call, the kernel can schedule another thread for execution.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 3

Many to One Model Many-to-one model maps many user level threads to one Kernel-level thread. Thread management is done in user space by the thread library. When thread makes a blocking system call, the entire process will be blocked. Only one thread can access the Kernel at a time, so multiple threads are unable to run in parallel on multiprocessors. If the user-level thread libraries are implemented in the operating system in such a way that the system does not support them, then the Kernel threads use the many-to-one relationship modes.

One to One Model There is one-to-one relationship of user-level thread to the kernel-level thread. This model provides more concurrency than the many-to-one model. It also allows another thread to run when a thread makes a blocking system call. It supports multiple threads to execute in parallel on microprocessors. Disadvantage of this model is that creating user thread requires the corresponding Kernel thread. OS/2, windows NT and windows 2000 use one to one relationship model.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 4

Q2B

What is TLB? why it is used?

[4]

Ans.

Figure shows Paging hardware with TLB The processor reads page table entries to convert virtual address to physical address. Usually a processor stores the information of page table entries in a hardware cache. This hardware cache consists of Translational look-aside buffers or TLBs. Whenever a processor needs to translate a virtual address, then it tries to fetch the page table entry information from TLBs. If it finds the entry then it proceeds further but if processor is not able to find any such entry then it tells the OS that a TLB miss has occurred and asks the OS to fix things up. To deliver this information of TLB miss to OS, some kind of exception mechanism is used which is processor dependent. Now, the OS finds the correct entry and updates the TLB entry with it. When the exception is cleared (after OS fixes the problem) then the processor again tries to search the TLBs for the entry and this time it finds a valid entry. Use:- The TLB is used with page tables in the following way. The TLB contains only a few of the page-table entries. When a logical address is generated by the CPU, its page number is presented to the TLB. If the page number is found, its frame number is immediately available and is used to access memory. The whole task may take less than 10 percent longer than it would if an unmapped memory reference were used. Q3.A Explain following algorithms of file management. i) iget

ii) iput

Ans.  The algorithm iget returns a previously identified inode, possibly reading it from disk via the buffer cache, and the algorithm iput releases the inode.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 5

[6]

algorithm iget input: file system inode number output: locked mode { while (not done) { { if (inode in inode cache) if (inode locked) { sleep (event inode becomes unlocked) ; continue I* loop back to while *I I* special processing for mount points (Chapter 5) *I if (inode on inode free list) remove from free list; increment inode reference count; return (in ode) ; · I* inode not in inode cache • I if (no inodes on free list) return (error) ; remove new inode from free list; reset inode number and file -system; remove inode from old hash queue, place on new one; read inode from disk (algorithm bread) ; initialize inode (e.g. reference count to l ) ; return (inode) ; } } i) iget :- Accessing lnodes The iget algorithm is used toward the beginning of system calls when a process first accesses a file. The algorithm returns a locked inode structure with reference count 1 greater than it had previously been. The in-core inode contains up-to-date information on the state of the file. The kernel unlocks the inode before returning from the system call so that other system calls can access the inode if they wish. The kernel identifies particular inodes by their file system and inode number and allocates in-core inodes at the request of higher-level algorithms. The algorithm iget allocates an in-core copy of an inode .The kernel maps the device number and inode number into a hash queue and searches the queue for the inode. If it cannot find the inode, it allocates one from the free list and locks it. The inode number and logical ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 6

device and computes the logical disk block that contains the inode according to how many disk inode fit into a disk block. The formula for computing is block num = ( (inode number -1) / number of inodes per block) + start block of inode list

The division operation returns the integer part of the quotient. If the kernel attempts to take an inode from the free list but finds the free list empty, it reports an error This is different from the philosophy the kernel follows for disk buffers, where a process sleeps until a buffer becomes free: Processes have control over the allocation of inodes at user level via execution of open and close system calls, and consequently the kernel cannot guarantee when an inode will become available. ii) iput :algorithm iput /* release (put) access to in-core inode */ input: pointer to in-core inode output: none { lock inode if not already locked; decrement inode reference. count; if (reference count == 0) { free disk blocks for file set file type to 0; free inode ; } if O node link count } if (file accessed or inode changed or file changed) update disk inode; put inode on free list; } release inode lock; } When the kernel releases an inode (algorithm iput) , it decrements its in-core reference count. If the count drops to 0, the kernel writes the inode to disk if the in-core copy differs from the disk copy. They differ if the file data has changed, if the file access time has changed, or if the file owner or access permissions have changed. The kernel places the inode on the free list of inodes,effectively caching the inode in case it is needed again soon. The kernel may also release all data blocks associated with the file and free the inode if the number of links to the file is 0.

Q3.B Give the details of Uarea field. Ans.  The u area contains additional information that controls the operation of a process. The process table entry and the u area are part of the context of a process. In other word, Every process has an entry in the kernel process table, and each process is allocated a u area that contains private data manipulated only by the kernel. The process table entry and the u area contain control and status information about the process. The u area is an extension of the process table entry.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 7

[4]

The u area contains information describing the process that needs to be accessible only when the process is executing. The important fields are • a pointer to the process table slot of the currently executing process, • parameters of the current system call, return values and error codes, • file descriptors for all open files, • internal 1/0 parameters, • current directory and current root , • process and file size limits. The kernel can directly access fields of the u area of the executing process but not of the u area of other processes. Internally, the kernel references the structure variable u to access the u area of the currently running process, and when another process executes, the kernel rearranges its virtual 11ddress space so that the structure refers to the u area of the new process. The implementation gives the kernel an easy way to identify the current process by following the pointer from the u area to its process table entry. OR Q4.A Why is the principle of locality crucial to the use of virtual memory? Explain with example. Ans. 

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 8

[4]

To prevent thrashing, user must provide a process with as many frames as it needs. The locality model states that, as a process executes, it moves from locality to locality. A locality is a set of pages that are actively used together (Above Figure). A program is generally composed of several different localities, which may overlap. For example, when a function is called, it defines a new locality. In this locality, memory references are made to the instructions of the function call, its local variables, and a subset of the global variables. When user exit the function, the process leaves this locality, since the local variables and instructions of the function are no longer in active use. It may return to this locality later. Thus, it is seen that localities are defined by the program structure and its data structures. The locality model states that all programs will exhibit this basic memory reference structure. Note :- ( the locality model is the unstated principle behind the caching ). If accesses to any types of data were random rather than patterned, caching would be useless. Suppose user allocate enough frames to a process to accommodate its current locality. It will fault for the pages in its locality until all these pages are in memory; then, it will not fault again until it changes localities. If user do not allocate enough frames to accommodate the size of the current locality, the process will thrash, since it cannot keep in memory all the pages that it is actively using. Q4.B lf the page address stream is {2, 3, 2, 1, 5, 2, 4, 5, 3, 2, 5, 2}, and frame size is 3. Identify the page faults occurred using F I F O, LRU. Ans.  Replacement Algorithms are 1. Optimal 2. LRU 3. FIFO 4. CLOCK The optimal policy selects for replacement that page for which the time to the next reference is the longest. It can be shown that this policy results in the fewest number of page faults [BELA66]. Clearly, this policy is impossible to implement, because it would require the operating system to have perfect knowledge of future events However, it does serve as a standard against which to judge real-world algorithms. Figure 8.15 gives an example of the optimal policy. The example assumes a fixed frame allocation (fixed resident set size) for this process of three frames. The execution of the process requires reference to five distinct pages. The page address stream formed by executing the program is 2 3 2 1 5 2 4 5 3 2 5 2 which means that the first page referenced is 2, the second page referenced is 3, and so on. The optimal policy produces three page faults after the frame allocation has been filled.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 9

[6]

The least recently used (LRU) policy replaces the page in memory that has not been referenced for the longest time. By the principle of locality, this should be the page least likely to be referenced in the near future. And, in fact, the LRU policy does nearly as well as the optimal policy. The problem with this approach is the difficulty in implementation. One approach would be to tag each page with the time of its last reference; this would have to be done at each memory reference, both instruction and data. Even if the hardware would support such a scheme, the over- head would be tremendous. Alternatively, one could maintain a stack of page references, again an expensive prospect. Above Figure shows an example of the behavior of LRU, using the same page address stream as for the optimal policy example. In this example, there are four page faults The first – in – first -out (FIFO) policy treats the page frames allocated to a process as a circular buffer, and pages are removed in round-robin style. All that is required is a pointer that circles through the page frames of the process. This is therefore due of the simplest page replacement policies to implement. The logic behind this choice, other than its simplicity, is that one is replacing the page that has been in memory the longest: A page fetched into memory a long time ago may have now fallen out of use. This reasoning will often be wrong, because there will often be regions of program or data that are heavily used throughout the life of a program. Those pages will be repeatedly paged in and out by the FIFO algorithm. Continuing our example in Figure the FIFO policy results in six page faults Note that LRU recognizes that pages 2 and 5 are referenced more frequently than other pages, whereas FIFO does not. Whereas the LRU policy does nearly as well as an optimal policy, it is difficult to implement and imposes significant overhead. On the other hand, the FIFO policy. Q5.A What are the problems in multiprocessor systems? provide solutions to overcome them. Ans.  UNIX system protects the integrity of kernel data -structures by two policies: The kernel cannot preempt a process and switch context to another process while executing in ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 10

[8]

kernel mode, and it masks out interrupts when executing a critical region of code,if an interrupt handler could corrupt kernel data structures. On a multiprocessor, however, if two or more processes execute simultaneously in the kernel on separate processors, the kernel could become corrupt in spite of the protective measures that suffice for uniprocessor systems. For example, consider the fragment of code that places a data structure (pointer bpi) after an existing structure (pointer bp). Suppose two processes execute the code simultaneously on different processors, such that processor A wants to place structure bpA after bp and processor B wants to place structure. bpB after bp . No assumptions can be made about the relative processor execution speed: the worst case is possible, where processor B could execute the four C statements before processor A can execute another statement. For example, handling an interrupt can delay execution of a code sequence on processor A. Corruption could occur, even though interrupts were blocked. The kernel must make sure that such corruption can never occur. If it were to leave a window open in which a corrupt situation could arise, no matter how rare,the kernel would be unsafe and its behavior unpredictable. There are three methods for preventing such corruption

1.Execute all critical activity on one processor, relying on standard uniprocessor methods for preventing corruption; 2.Serialize access to critical regions of code with locking primitives; 3. Redesign algorithms to avoid contention for data structures. Two methods to protect the kernel from corruption, SOLUTION WITH MASTER AND SLAVE PROCESSORS

one processor, called the master, can execute in kernel mode and the other processor, called the slave, executes only in user mode. Implementation contained two machines, the technique extends to systems with one master and several slaves. The master processor is responsible for handling all system calls and interrupts. Slave processors execute processes in user mode and inform the master processor when a process makes a system call. The scheduler algorithm decides which processor should execute a process. A new field in the process table designates the processor ID that a process must run on; for simplicity, assume it indicates either master or slave. SOLUTION WITH SEMAPHORES

Another method for supporting UNIX systems on multiprocessor configurations is to partition the kernel into critical regions such that at most one processor can execute code in a critical region at a time. Such multiprocessor systems were designed using semaphores, to partition the kernel into critical regions . There are two issues: How to implement semaphores and where to define critical regions. The various algorithms in uniprocessor UNIX systems use a sleep-lock to keep other processes out of a critical region in case the first process later goes to sleep inside the critical region. The mechanism for setting the lock is while ( lock is set ) /* test operation */ sleep ( condition until lock, i s free ) ; set lock: and the mechanism for unlocking the lock is · free lock; wake up all processes sleeping on condition lock set; Sleep-locks delineate some critical regions, but they do not work on multiprocessor systems,To prevent this situation, the locking primitive must be atomic: The actions of ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 11

testing the status of the lock and setting the lock must be done as a single, indivisible operation, such that only one process can manipulate the lock at a time. Q5.B Explain IPC mechanisms used in System V.

[8]

Ans.  interprocess communication mechanisms allow arbitrary processes to exchange data and synchronize execution. Several forms of interprocess communication,such as pipes, named pipes, and signals. System V IPC package are messages, shared memory, and semaphores. SYSTEM V IPC The UNIX System V IPC package consists of three mechanisms. Messages allow processes to send formatted data streams to arbitrary processes, shared memory allows processes to share parts of their virtual address space, and semaphores allow processes . to synchronize execution. Implemented as a unit, they share common properties. • Each mechanism contains a table whose entries describe all instances of the mechanism • Each entry contains a numeric key , which is its user-chosen name. • Each mechanism contains a "get" system call to create a new entry or to retrieve an existing one, and the parameters to the calls include a key and flags. The kernel searches the proper table for an entry named by the key. Processes can call the "get" system calls with the key IPC_PRIVATE TE to assure the return of an unused entry. • For each IPC mechanism, the kernel uses the following formula to find the index into the table of data structures from the descriptor: index = descriptor •





modulo ( number of entries in table ) Each IPC entry has a permissions structure that includes the user ID and group ID of the process that created the entry, a user and group ID set by the "control" system call ( below ) , and a set of read-write-execute permissions for user, group, and others, similar to the file permission modes. Each entry contains other status information, such as the process ID of the last process to update the entry (send a message, receive a message, attach shared memory, and so on ) , and the time of last access or update. Each mechanism contains a "control" system call to query status of an entry, to Private set status information, or to remove the entry from the system. When a process queries the status of an entry, the kernel verifies that the process has read permission and then copies data from the table entry to the user address.

OR Q6.A What is process tracing? Mention its advantages and disadvantages. Ans.  The UNIX system provides a primitive form of interprocess communication for tracing processes, useful for debugging. A debugger process, such as sdb, spawns a process to be traced and controls its execution with the ptrace system call, setting and clearing break points, and reading and writing data in its virtual address space. Process tracing thus consists of synchronization of the debugger process and the traced process and controlling the execution of the traced process. The ptrace system call and, as a result, the kernel sets a trace bit in the child process table entry. Waiting to be awakened by the traced process. When the traced process awakens the debugger, the debugger returns from wait , reads user input commands, and converts them to a series of ptrace calls to control the child (traced) process. The syntax of the ptrace system call is ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 12

[8]

ptrace (cmd, pid, addr, data) ; Advantages • When executing the ptrace system call, the kernel verifies that the debugger has a child whose ID is pid and that the child is in the traced state and then uses a global trace data structure to transfer data between the two processes. • It locks the trace data structure to prevent other tracing processes from overwriting it, copies cmd, addr, and data into the data structure, wakes up the child process and puts it into the "ready-to-run" state, then sleeps until the child responds. • When the child resumes execution (in kernel mode) , it does the appropriate trace command, writes its reply into the trace data structure, then awakens the debugger. • If the debugger process is not sleeping in the wait system call when the child enters the trace state, it will not discover its traced child until it calls wait , at which time it returns immediately and proceeds Disadvantage The use of ptrace for process tracing is primitive and suffers several drawbacks. • The kernel must do four context switches to transfer a word of data between a debugger and a traced process: The kernel switches context in the debugger in the ptrace call until the traced process replies to a query, switches context to and from the traced process, and switches context back to the debugger process with the answer to the ptrace call. • A debugger process can trace several child processes simultaneously, although this feature is rarely . used in practice. More critically, a debugger can only trace child processes: If a traced child forks, the debugger has no control over the grandchild, a severe handicap when debugging sophisticated programs. • A debugger cannot trace a process that is already executing if the debugged process had not called ptrace to let the kernel know that it consents to be traced. • It is impossible to trace setuid programs, because users could violate security by writing their address space via ptrace and doing illegal operations. Q6.B Explain in short - pipe, semaphore, signal and mutex. Ans. 

1) Pipe:- Pipes allow transfer of data between processes in a first-in-first-out manner (FIFO) , and they also allow synchronization of process execution.

Their implementation allows processes to communicate even though they do not know what processes are on the other end of the pipe. The traditional implementation qf pipes uses the file system for data storage. There are two kinds of pipes: named pipes and, for lack of a better term, unnamed pipes, which are identical except for the way that a process initially accesses them. Processes use the open system call for named pipes, but the pipe ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 13

[8]

system call to create an unnamed pipe. Afterwards, processes use the regular system calls for files, such as read, write, and close when manipulating pipes. Only related processes, descendants of a process that issued the pipe call, can share access to unnamed pipes. 2) Semaphore :- The semaphore system calls allow processes to synchronize execution by doing a set of operations atomically on a set of sema phores . Before the implementation of semaphores, a process would create a lock- file with the wanted to lock a resource: The create would process assume that another creat system call if it fails if the file already exists, and the process had the resource locked . The major disadvantages of this approach are that the process does not know when to try again, and lock files may inadvertently be left behind when the system crashes or is rebooted. Dekker algorithm that describes an implementation of semaphores , integer- valued objects that have two atomic operations defined for them. The semaphore system calls are semget to create and gain access to a set of semaphores, semctl to do various control operations on the set, and semop to manipulate the values of semaphores. 3) Signals:Signals inform processes of the occurrence of asynchronous events. Processes may send each other signals with the kill system call, or the kernel may send signals internally. There are 19 signals in the System V (Release 2 ) UNIX system that can be classified as follows •

Signals having to do with the termination of a process, sent when a process exits or when a process invokes the signal system call with the death of child parameter;



Signals having to do with process induced exceptions such as when a process accesses an address outside its virtual address space.



Signals having to do with the unrecoverable conditions during a system call, such as running out of system resources.



Signals caused by an unexpected error condition during a system call, such as making a nonexistent system call.



Signals originating from a process in user mode, such as When a process wishes to receive an alarm signal after a period of time, or when processes send arbitrary signals to each other with the kill system call.



Signals related to terminal interaction such as when a user hangs up a terminal (or the "carrier" signal drops on such a line for any reason) ,or when a user presses the "break" or "delete" keys on a terminal keyboard;



Signals for tracing execution of a process.

4) Mutex :On some systems, binary semaphores are known as mutex locks, as they are locks that provide mutual exclusion. do {  waiting(mutex);  // critical section      signal(mutex); Signals:-

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 14

Signals inform processes of the occurrence of asynchronous events. Processes may send each other signals with the kill system call, or the kernel may send signals internally. There are 19 signals in the System V (Release 2 ) UNIX system that can be classified as follows •

Signals having to do with the termination of a process, sent when a process exits or when a process invokes the signal system call with the death of child parameter;



Signals having to do with process induced exceptions such as when a process accesses an address outside its virtual address space.



Signals having to do with the unrecoverable conSignals:-



Signals inform processes of the occurrence of asynchronous events. Processes may send each other signals with the kill system call, or the kernel may send signals internally. There are 19 signals in the System V (Release 2 ) UNIX system that can be classified as follows



Signals having to do with the termination of a process, sent when a process exits or when a process invokes the signal system call with the death of child parameter;



Signals having to do with process induced exceptions such as when a process accesses an address outside its virtual address space.



Signals having to do with the unrecoverable conditions during a system call, such as running out of system resources.



Signals caused by an unexpected error condition during a system call, such as making a nonexistent system call.



Signals originating from a process in user mode, such as When a process wishes to receive an alarm signal after a period of time,Signals:-



Signals inform processes of the occurrence of asynchronous events. Processes may send each other signals with the kill system call, or the kernel may send signals internally. There are 19 signals in the System V (Release 2 ) UNIX system that can be classified as follows



Signals having to do with the termination of a process, sent when a process exits or when a process invokes the signal system call with the death of child parameter;



Signals having to do with process induced exceptions such as when a process accesses an address outside its virtual address space.



Signals having to do with the unrecoverable conditions during a system call, such as running out of system resources.



Signals caused by an unexpected error condition during a system call, such as making a nonexistent system call.



Signals originating from a process in user mode, such as When a process wishes to receive an alarm signal after a period of time, or when processes send arbitrary signals to each other with the kill system call.



Signals related to terminal interaction such as when a user hangs up a terminal (or the "carrier" signal drops on such a line for any reason) ,or when a user presses the "break" or "delete" keys on a terminal keyboard;

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 15



Signals for tracing execution of a process.



or when processes send arbitrary signals to each other with the kill system call.



Signals related to terminal interaction such as when a user hangs up a terminal (or the "carrier" signal drops on such a line for any reason) ,or when a user presses the "break" or "delete" keys on a terminal keyboard;



Signals for tracing execution of a process.



ditions during a system call, such as running out of system resources.



Signals caused by an unexpected error condition during a system call, such as making a nonexistent system call.



Signals originating from a process in user mode, such as When a process wishes to receive an alarm signal after a period of time, or when processes send arbitrary signals to each other with the kill system call.



Signals related to terminal interaction such as when a user hangs up a terminal (or the "carrier" signal drops on such a line for any reason) ,or when a user presses the "break" or "delete" keys on a terminal keyboard;



Signals for tracing execution of a process. // remainder section 

 }while (TRUE); One can use binary semaphores to deal with the critical-section problem for multiple processes. The n processes share a semaphore, mutex, initialized to 1. Each process P, is organized as shown above. The mutex semaphore provides mutual exclusion for accesses to the buffer pool and is initialized to the value 1. In reader writer problem , the mutex semaphore is used to ensure mutual exclusion when the variable readcount is updated. The readcount variable keeps track of how many processes are currently reading the object. Q7.A What is AWK scripting? Write an AWK script to print the mutex semaphore is used to ensure mutual exclusion when the variable readcount is updated. The readcount variable keeps track of how many processes are currently reading the object squares of numbers from 1 to 10.

[8]

Ans.  Q7.B What is secure boot? State the difference between BIOS and UEFI. Ans.  Unified extensible firmware interface Microsoft Secure Boot is a component of Microsoft's Windows 8 operating system that relies on the UEFI specification's secure boot functionality to help prevent malicious software applications and "unauthorized" operating systems from loading during the system start-up process. Intel’s extensible firmware interface (EFI) project aims to replace the rickety conventions of PC BIOSes with a more modern and functional architecture. Although systems that use full EFI firmware are still uncommon, EFI’s partitioning scheme has gained widespread support among operating systems. The main reason for this success is ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 16

[8]

that MBR does not support disks larger than 2TB in size. Since 2TB disks are already widely available, this problem has become a matter of some urgency. The EFI partitioning scheme, known as a “GUID partition table” or GPT, removes the obvious weaknesses of MBR. It defines only one type of partition, and you can create arbitrarily many of them. Each partition has a type specified by a 16-byte ID code (the globally unique ID, or GUID) that requires no central arbitration. Significantly, GPT retains primitive compatibility with MBR-based systems by dragging along an MBR as the first block of the partition table. This “fakie” MBR makes the disk look like it’s occupied by one large MBR partition (at least, up to the 2TB limit of MBR). It isn’t useful per se, but the hope is that the decoy MBR may at least prevent naïve systems from attempting to reformat the disk. Versions of Windows from the Vista era forward support GPT disks for data, but only systems with EFI firmware can boot from them. Linux and its GRUB boot loader have fared better: GPT disks are supported by the OS and bootable on any system. Intel-based Mac OS systems use both EFI and GPT partitioning. Solaris understands GPT partitioning, and ZFS uses it by default. However, Solaris boot disks cannot use GPT partitioning. Although GPT has already been well accepted by operating system kernels, its support among disk management utilities is still spotty. GPT remains a “bleeding edge” format. There is no compelling reason to use it on disks that don’t require it (that is, disks 2TB in size or smaller). OR Q8.A What is grep Utility? What are the grep variations? Explain with example. Ans.  The grep utilities are a family of Unix tools, including grep , egrep , and fgrep , that perform repetitive searching tasks. The tools in the grep family are very similar, and all are used for searching the contents of files for information that matches particular criteria grep:-

grep [option] pattern {filename}* grep searches the named files or standard input and prints each line that contains an instance of the pattern. grep interprets the same regular expressions ^ and $ "anchor" the pattern to the beginning (^) or end ($) of the line. regular expressions meta-characters overlap with shell meta-characters , so it's always a good idea to enclose grep patterns in single quotes, to suppress interpretation by the shell. $ grep From $MAIL

locates lines containing From in your mailbox

$ grep '^From'$MAIL prints lines that begin with From in your mailbox grep examples print lines that begin with mary $ who | grep '^mary' print lines that end with mary $ who | grep 'mary$’ list files others can read and write $ls -l | grep '^. . . . . . .rw’ ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 17

[8]

Q8.B What is make utility? Explain it with example. Consider your own make file.

[8]

Ans.  The make utility is a software engineering tool for managing and maintaining computer programs. Make provides help when the program consists of many component files. The purpose of the make utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them. The make written by Richard Stallman and Roland McGrath, and is currently maintained by Paul Smith. Make is not limited to programs. User can use it to describe any task where some files must be updated automatically from others whenever the others change. To prepare to use make, User must write a file called the makefile that describes the relationships among files in user program, and the states the commands for updating each file. In a program, typically the executable file is updated from object files, which are in turn made by compiling source files.

make syntax make [ -f makefile ] [ options ] ... [ targets ] ... Example make would typically use this rule to update the "file.txt" target if "file.html" were newer: make file.txt

Q9.A Enlist different characteristics of real time system and explain. Ans. 

Characteristics of a RTS 1) Large and complex — vary from a few hundred lines of assembler or million lines of Ada estimated for the Space Station Freedom . (Ada is a programming language) 2) Concurrent control of separate system components devices operate in parallel in the real-world; better to model this parallelism by concurrent entities in the program 3) Facilities to interact with special purpose hardware need to be able to program devices in a reliable and abstract way . 3) Mixture of Hardware/Software: some modules implemented in hardware, even whole

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 18

[6]

systems. 4) Extreme reliability and safety embedded systems typically control the environment in which they operate; failure to control can result in loss of life, damage to environment or economic loss 5) Guaranteed response times — we need to be able to predict with confidence the worst case response times for systems; efficiency is important but predictability is essential The Features of Real Time System are • Fast process or thread switch • Small size (with its associated minimal functionality) • Ability to respond to external interrupts quickly • Multitasking with interprocess communication tools such as semaphores, signals, and events • Use of special sequential files that can accumulate data at a fast rate • Preemptive scheduling based on priority • Minimization of intervals during which interrupts are disabled • Primitives to delay tasks for a fixed amount of time and to pause/resume tasks • Special alarms and timeouts Q9.B Explain static priority-driven preemptive approach for real time scheduling. Ans.  The heart of a real-time system is the short-term task scheduler. In designing such a scheduler, fairness and minimizing average response time are not paramount. Important is that all hard real-time tasks complete (or start) by their deadline and that as many as possible soft real-time tasks also complete (or start) by their deadline.

Above Figure illustrates a spectrum of possibilities. In a preemptive scheduler that uses simple round-robin scheduling, a real-time task would be added to the ready queue to await its next timeslice. In this case, the scheduling time will generally be unacceptable for real-time applications. Alternatively, in a nonpreemptive scheduler, we could use a ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 19

[6]

priority scheduling mechanism, giving real-time tasks higher priority. In this case, a real-time task that is ready would be scheduled as soon as the current process blocks or runs to completion ( Figure b ). This could lead to a delay of several seconds if a slow, low-priority task were executing at a critical time. When a preemption point occurs, the currently running task is preempted if a higher-priority task is waiting. This would include the preemption of tasks that are part of the operating system kernel. Such a delay may be on the order of several milliseconds ( Figure c ). Static priority-driven preemptive approaches: Again, a static analysis is performed, but no schedule is drawn up. Rather, the analysis is used to assign priorities to tasks, so that a traditional priority-driven preemptive scheduler can be used. It makes use of the priority-driven preemptive scheduling mechanism common to most non-real-time multiprogramming systems. In a non-real-time system, a variety of factors might be used to determine priority. For example, in a time-sharing system, the priority of a process changes depending on whether it is processor bound or I/O bound. In a real-time system, priority assignment is related to the time constraints associated with each task. One example of this approach is the rate monotonic algorithm , which assigns static priorities to tasks based on the length of their periods. Q9.C Compare Hard, soft and Firm real time systems.

[6]

Ans.  A hard real-time task is one that must meet its deadline; otherwise it will cause unacceptable damage or a fatal error to the system. A soft real-time task has an associated deadline that is desirable but not mandatory; it still makes sense to schedule and complete the task even if it has passed its deadline. Another characteristic of realtime tasks is whether they are periodic or aperiodic. An aperiodic task has a deadline by which it must finish or start, or it may have a constraint on both start and finish time. In the case of a periodic task, the requirement may be stated as “once per period T” or “exactly T units apart.” The heart of a real-time system is the short-term task scheduler. In designing such a scheduler, fairness and minimizing average response time are not paramount. What is important is that all hard real-time tasks complete (or start) by their deadline and that as many as possible soft real-time tasks also complete (or start) by their deadline. Priority: Measures relative importance of the task. Hard real-time tasks may have an “absolute” priority, with the system failing if a deadline is missed. If the system is to continue to run no matter what, then both hard and soft realtime tasks may be assigned relative priorities as a guide to the scheduler. For Ex. simulators for military aircraft, Most hard real-time systems also have soft real-time components, such as certain noncritical displays and built-in self tests that can execute at lower priority levels to absorb the processor time that is not used with RMS scheduling of hard real-time tasks. OR Q10.A Explain data structures used in Linux scheduling. Ans.  The three Linux scheduling classes are • SCHED_FIFO: First-in-first-out real-time threads • SCHED_RR: Round-robin real-time threads • SCHED_OTHER: Other, non-real-time threads

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 20

[6]

To understand Linux scheduling one must know what is runqueue? The runqueue is:When the scheduler assigns the CPU to the process, it leaves the process descriptor in its current position in the runqueue list. Each CPU has a runqueue made up of 140 priority lists that are serviced in FIFO order. Tasks that are scheduled to execute are added to the end of their respective runqueue's priority list The basic data structure in the scheduler is the runqueue. The runqueue is defined in kernel/sched.c as struct runqueue. The runqueue is the list of runnable processes on a given processor; there is one runqueue per processor. Each runnable process is on exactly one runqueue. The runqueue additionally contains per-processor scheduling information. Consequently, the runqueue is the primary scheduling data structure for each processor. Why kernel/sched.c and not include/linux/sched.h? Because it is desired to abstract away the scheduler code and provide only certain interfaces to the rest of the kernel. Because runqueues are the core data structure in the scheduler, a group of macros is used to obtain specific runqueues. The macro cpu_rq(processor) returns a pointer to the runqueue associated with the given processor. Similarly, the macro this_rq() returns the runqueue of the current processor. Finally, the macro task_rq(task) returns a pointer to the runqueue on which the given task is queued. Before a runqueue can be manipulated, it must be locked . Because each runqueue is unique to the current processor, it is rare when a processor desires to lock a different processor's runqueue (it does happen, however, as we will see). The locking of the runqueue prohibits any changes to it while the lock-holder is reading or writing the runqueue's members. The most common way of locking a runqueue is when you want to lock the runqueue a specific task runs on.

The Linux Scheduling Algorithm The Linux scheduler is defined in kernel/sched.c. The new scheduler was designed to accomplish specific goals: •

Implement fully O(1) scheduling. Every algorithm in the new scheduler completes in constant-time, regardless of the number of running processes or any other input.



Implement perfect SMP scalability. Each processor has its own locking and individual runqueue.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 21



Implement improved SMP affinity. Naturally attempt to group tasks to a specific CPU and continue to run them there. Only migrate tasks from one CPU to another to resolve imbalances in runqueue sizes.



Provide good interactive performance. Even during considerable system load, the system should react and schedule interactive tasks immediately.



Provide fairness. No process should find itself starved of timeslice for any reasonable amount of time. Likewise, no process should receive an unfairly high amount of timeslice.



Optimize for the common case of only 1-2 runnable processes, yet scale well to multiple processors each with many processes.

The new scheduler accomplished these goals. Q10.B Write short note on frame of references for handheld system. Ans.  The common frame of reference to characterize handheld systems. Basically need to identify the quality parameters that can help in making the comparisons. Their are many operating systems for handheld systems. It is important to also to be able to characterize such systems across some quality parameters. A general statement that can be made: Always look up ISO standards as a benchmark requirement for all the features and quality parameters. Here address precisely this aspect. 1 Functionality: It is important to explore the extent of interoperability, accuracy in features related to rendering,r of media (audio/video/image). 2 Extensibility to incorporate newer services: The basic consideration should be how easy it is to change or upgrade services. An open system is likely to be more amenable to changes and upgrade. On this scale Android and Symbian have rich platforms. The headless design of Symbian and open community support makes this easier in comparison to RIM’s Blackberry. 3 Maintainability from servicing point of view: The important consideration here would be the diagnostic procedures for fault detection and location. The system should have ways to determine the likely cause of failure as well. In addition, it should support easy install and offer mechanisms to test all installed services. In fact, following the installation it should coexist with legacy applications which are still resident with the system. 4 Power levels of operation and energy efficiency: The battery life is critical. In fact, the new approach to power management suggests that a high priority task may obtain higher levels of energy-Le. get scheduled more often at the expense of lower clock cycles for low priority jobs. In other words, the energy drain and usage is regulated by the urgency of the task. Finally, it is important to recognize that individual uses like music, video, graphics rendering, operations in vibratory ambiance or hostile weather conditions (rain or snow) required different standard. 5 Usability of device: Oftentimes the choice may be based on the most important usage pattern. For instance, Blackberry offers for heavy duty e-mail usage, where as i-phone is ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 22

[6]

media rich for music and videos. Palm OS is rich on personal information management, etc. Other important aspects of usability relate to ease with which one can learn and discovery features . These could be used to compare and contrast devices on quality parameters. 6 Security of services: Most phones provide good security. Symbian stands out on the repertoire of public key infrastructure. Also, its component-based security services are extensible. 7 Reliability of operation: The points to consider would be recovery and reboots. How often does one need to reboot when applications switch becomes a critical consideration. Win CE has a stable and reliable office suite support which integrates across applications very well. Q10.C Compare Windows NTFS and ReFS file systems. Ans.  ReFS – Resilient File System – is a Microsoft proprietary file system introduced with Windows Server 2012. It’s not a substitute of NTFS, the file system released in 1993 with Windows NT 3.1 and revised many times, still the only available for the installation of a Windows operating system. The two file systems are a complement of each other, ReFS has been introduced to safely store large amount of data. It’s the perfect solution for data shares, archives, backups and to store Hyper-V virtual machine disks. The goals of Microsoft in building ReFS • • • • •

Maintain a high level of compatibility with NTFS; Make it able to verify and auto-correct data Optmize for extreme scale Make it able to stay always online, even in case of partial corruptions Provide a full end-to-end resiliency architecture when used in conjunction with the Storage Spaces feature

The key features of ReFS are as follows • • • • • • • • •

Metadata integrity with checksums Integrity streams providing optional user data integrity Allocate on write transactional model for robust disk updates (also known as copy on write) Large volume, file and directory sizes Storage pooling and virtualization makes file system creation and management easy Data striping for performance (bandwidth can be managed) and redundancy for fault tolerance Disk scrubbing for protection against latent disk errors Resiliency to corruptions with “salvage” for maximum volume availability in all cases Shared storage pools across machines for additional failure tolerance and load balancing

NTFS(New Technology File System) Windows file system ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 23

[6]

Even though Microsoft made ReFS, but still many features of NTFS are not compatible with ReFS For example, ReFS not able to hard links support and this means it can’t be used to run the operating system and some applications. Thus NTFS is the only solution for operating system. 1. The features of NTFS listed below 2. Supports Case-sensitive filenames 3. Preserves Case of filenames 4. Supports Unicode in filenames 5. Preserves & Enforces ACL’s 6. Supports Sparse files 7. Supports Reparse Points 8. Supports Open By FileID 9. Supports USN Journal 10. Supports Hard Links 11. Supports file-based Compression 12. Supports Disk Quotas 13. Supports Object Identifiers 14. Supports Encrypted File System 15. Supports Named Streams 16. Supports Transactions 17. Supports Extended Attributes NTFS supported all the 17 features while ReFS supported only first 8 features of NTFS, rest of 9 to 17 features are not supported by ReFS. Note:- This literature is only for private circulation.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 24

Matoshri College of Engineering & R. C. Nashik Department of Computer Engineering. Subject :- OPERATING SYSTEM DESIGN. Semester:- 5 Subject I/c :- Mr. Ranjit Gawande. MODEL ANSWER – FOR April May  15

Model Ans. Paper for Operating System Design 2012 Pat. Q1.A Explain in short - BIOS, MBR and init( ) process. Ans.

Repeated

Q1.B Explain Kernel Structure. With neat diagram. Ans.

[6]

[4]

Repeated

OR Q2A

Explain with neat diagram process states and transition.

Ans.

Repeated

Q2B

What is disk inode? State the difference between disk inode and in-core inode.

Ans.

Repeated

Q3.A Why is the principle of locality crucial to the use of virtual memory? Explain with example.

[5]

[5]

[4]

Ans.  Rep Q3.B Give the details of U-area field.

[6]

Ans.  Repeated OR Q4.A Explain the race condition in assigning inodes.

[4]

Ans.  Q4.B Compare and contrast paging vs segmentation. Ans.  ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 25

[6]

Q5.A What is ptrace system call? Explain Process tracing in detail.

[8]

Ans.  Q5.B Explain the term signal and elaborate the various circumstances under which signals of the various classes are used. Ans. 

Signals:-Signals inform processes of the occurrence of asynchronous events. Processes may send each other signals with the kill system call, or the kernel may send signals internally. There are 19 signals in the System V (Release 2 )

Fig. Shows checking & handling signal in process state diagram. The circumstances under which signals of the various classes are used. The treatment of signals has several facets, namely how the kernel sends a signal to a process, how the process handles a signal, and how a process controls its reaction to signals. To send a signal to a process, the kernel sets a bit in the signal field of the process table entry, corresponding to the type of signal received: If the process is asleep at an interruptible priority, the kernel awakens it. The job of the sender (process or kernel) is complete. A process can remember different types of signals, but it has no memory of how many signals it receives of a particular type. For example, if a process receives a hangup signal and a kill signal, it sets the appropriate bits in the process table signal field, but it cannot tell how many instances of the signals it receives. The kernel checks for receipt of a signal when a process is about to return from kernel mode to user mode and when it enters or leaves the sleep state at a suitably low scheduling priority (Figure shown above) . The kernel handles signals only when a process returns from kernel mode to user mode. Thus, a signal does not have an instant effect on a process running in kernel mode. If a process is running in user mode, and the kernel handles an interrupt that causes a signal to be sent to the process, the kernel will recognize and handle the signal when it returns from the interrupt. Thus, a process never executes in user mode before handling outstanding signals.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 26

[8]

OR Q6.A Write short notes on: i) Tunis System.

ii) Shared memory.

Ans.  i) Tunis System.:- TUNIS (Toronto University System) was a Unix-like operating system, developed at the University of Toronto in the early 1980s. TUNIS was a portable operating system compatible with Unix V7, but with a completely redesigned kernel, written in Concurrent Euclid. The Tunis system has a user interface that is compatible to that of the UNIX system, but its nucleus, written in the language Concurrent Euclid, consists of kernel processes that control each part of the system. The Tunis system solves the mutual exclusion problem because only one instance of a kernel process can run at a time, and because kernel processes do not manipulate the data structures of other processes. Kernel processes are activated by queuing messages for input, and Concurrent Euclid implements monitors to prevent corruption of the queues. A monitor is a procedure that enforces mutual exclusion by allowing only one process at a time to execute the body of the procedure. They differ from, semaphores because they force modularity (the P and V are at the entry and exit points of the monitor routine) and because the compiler generates the synchronization primitives. However, the internal structure of the Tunis system differs radically from traditional implementations of the UNIX system. ii) Shared memory.:-

Processes can communicate directly with each other by sharing parts of their virtual address space and then reading and writing the data stored in the shared memory. The system calls for manipulating shared memory are similar to the system calls for messages. The shmget system call creates a new region of shared memory or returns an existing one, the shmat system call logically attaches all region to the virtual address space of a process, the shmdt system call detaches a region from the virtual address space of a process, and the shmctl system call manipulates various parameters associated with the shared memory. Processes read and write shared memory using the same machine instructions they use to read and write regular memory. After attaching shared memory, it becomes part of the virtual address space of a process, accessible in the same way other virtual addresses are; no system calls are needed to access data in ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 27

[8]

shared memory. The syntax of the shmget system call is shmid = shmget (key, size, flag) ; where size is the number of bytes in the region. The kernel searches the shared memory table for the given key: if it finds an entry and the permission modes are acceptable, it returns the descriptor for the entry. If it does not find an entry and the user had set the IPC_CREAT flag tp create a new region, the kernel verifies that the size is between system-wide minimum and maximum values and then allocates a region data structure using algorithm al/ocreg (Section 6.5.2) . The kernel saves the permission modes, size, and a pointer to the region tabk entry in the shared memory table (Figure 1 1 .9) and sets a flag there to indicate that no memo,ry is associated with the region. It allocates memory (page tables and so on) for the region only when a process attaches the region to its address space. The kernel also sets a flag on the region table entry to indicate that the region should not be freed when the last process attached to it exits. Thus, data in shared memory remains intact even though no processes include it as part of their virtual address space. A process attaches a shared memory region to its virtual address space with the shmat system call: virtaddr = shmat Gd, addr, flags) ; Id, returned by a previous shmget system call, identifies the shared memory region, addr is the virtual address where the user wants to attach the shared memory, and flags specify whether the region is read-only and whether the kernel should round off the userspecified address. The return value, virtaddr, is the virtual address where the kernel attached the region, not necessarily the value requested by the process.

Q6.B What is deadlock? Explain necessary conditions to occur the deadlock? Ans. 

Figure shows Deadlock because of Reversed Order of Locking To avoid a deadlock, the kernel must block out interrupts that execute a spin lock. Otherwise, a process could lock a semaphore and be interrupted before it unlocks the semaphore , if the interrupt handler attempts to lock the same , semaphore using a spin ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 28

[8]

lock, the kernel deadlocks itself, (shown in above Figure) for example, the value of the semaphore is at most 0 when the interrupt occurs, so the CP in the interrupt handler will always be false. The situation is avoided by blocking out interrupts while the process has the semaphore locked. One final danger is worthy of mention. If the swapper attempts to swap out a process but cannot find space on the swap device, a system deadlock could arise if the following four conditions are met: All processes in main memory are asleep, all "ready-to-run" processes are swapped out, there is no room on the swap device for new processes, and there is no room in main memory for incoming processes. Q7.A What is make utility? Explain it with example. Consider your own makefile. Ans.  Make avoids unnecessary compilation. It checks recency of an object code relative to its source. Suppose a certain source file has been modified but is not re-compiled. Make would find that the compiled file is now older than the source. So, the dependency of the object on the source will ensure re-compilation of source to generate new object file. To ensure consistency, make uses a rule-based inferencing system to determine the actions needed. It checks on object code dependencies on sources by comparing its recency with regard to time of their generation or modification. Actions in command lines ensure consistency using rules of dependence. Any time a (.c) or a (.h) file is modified, all the dependent objects are recreated. Now we can state how make works: make ensures that a file, which is dependent on its input files, is consistent with the latest definitions prevailing in the input files. This also ensures that in the ensuing compilation, linking can be fully automated by Make. Thus, it helps in avoiding typing out long error prone command sequences. Even the clean-up process following re-compilation can be automated. As a simple case, consider the following “helloworld” program. Which demonstrate the use of a makefile through this example. Step1: Create a program file helloWorld.c as shown below: #include include main() { printf("HelloWorld \n "); } Step2: Prepare a file called “makefile” as follows: # This may be a comment hello: helloWorld.c cc -o hello helloWorold.c This is all in this makefile Step3: Now give a command as follows:

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 29

[8]

make Step4: Execute helloWorld to see the result. To see the effect of make, first repeat the command make and note how ma ke responds to indicate that files are up-to-date needing no recompilation. Now modify the program. Let us change the statement in printf to: printl("helloWorld here I come ! \n") Now execute make again To force make to re-compile a certain file one can simply update its time by a UNIX touch command as given below: touch It this updates its recent modification time *1 Make command has the following other useful options: 1) -n option: With this option, make goes through all the commands in makefile without executing any of them. Such an option is useful to just check out the makefile itself. 2) -p option: With this option, make prints all the macros and targets as it progresses. 3) -s option: With this option, make is silent. Essentially, it is the opposite of -p option. 4) -i option: With this option, make ignores any errors or exceptions which are thrown up. This is indeed very helpful in a development environment. During development, sometimes one needs to focus on a certain part of a program. One may have to do this with several modules in place. In these situations, one often wishes to ignore some obvious exceptions. This ensures that one is not bogged down in reaching the point of test which is in focus at the moment.

Q7.B Explain with example Linux utilities - grep, egrep, fgrep and sort. Ans.  Sort:- sorts a file in ascending or descending order based on one or more sort fields, and works as follows:

sort [options]{filename}* sort utility : common options sort file

sort file by line, in ASCII order

sort -r

reverse normal order

sort -n

sort in numeric (arithmetic) order starting at the beginning of line

sort -nr

sort in reverse numeric order

grep:-

grep [option] pattern {filename}* grep searches the named files or standard input and prints each line that contains an ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 30

[8]

instance of the pattern. grep interprets the same regular expressions ^ and $ "anchor" the pattern to the beginning (^) or end ($) of the line. regular expressions meta-characters overlap with shell meta-characters , so it's always a good idea to enclose grep patterns in single quotes, to suppress interpretation by the shell. $ grep From $MAIL

locates lines containing From in your mailbox

$ grep '^From'$MAIL prints lines that begin with From in your mailbox grep examples print lines that begin with mary $ who | grep '^mary' print lines that end with mary $ who | grep 'mary$’ list files others can read and write $ls -l | grep '^. . . . . . .rw’ egrep is an extended grep that works on extended regular expression,accepts: +

one or more occurrences

?

zero or one occurrence

pat1| pat2 "or" op matches on either pat1 or pat2 ( r)

regular expression r , can be nested

(xy)*

matches any of the empty string, xy, xyxy, xyxyxy and so on

fgrep utilities • • • •

fgrep searches for many literal strings simultaneously. It does not work with *. Both, fgrep and egrep have -f option, to read patterns stored in a file. In file, newlines separate patterns to be searched for simultaneously.

OR Q8.A

Write a short note on: i) Mork Manager. ii) Shim Manager.

Ans.  i) Mork Manager. UEFI (Unified Extensible Firmware Interface ) Secure Boot work with Linux too. In reality, Linux has some innovative uses for Secure Boot, such as the Machine Owner Key (MOK) . A Machine Owner Key (MOK) is a type of key that a user generates and uses to sign

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 31

[8]

an EFI binary (Extensible Firmware Interface). The point of a MOK is to give users the ability to run locally-compiled kernels, boot loaders not delivered by the distribution maintainer, Linux (suse) presented the MOK concept with Intel Developer Forum (IDF). MOK is a way for the machine owner to have ownership over the platform’s boot process, so they can install a custom kernel or kernel modules and still work with UEFI Secure Boot. MOK has been part of the Linux (suse) UEFI Secure Boot. If the user (machine owner) wants to replace any components of the boot process, Machine Owner Keys (MOKs) are to be used. The mokutils tool will help with signing components and managing MOKs. ii) Shim Manager. The enrollment process begins with rebooting the machine and interrupting the boot process (e.g., pressing a key) when shim loads. shim will then go into enrollment mode, allowing the user to replace the default Linux (suse) key with keys from a file on the boot partition. If the user chooses to do so, shim will then calculate a hash of that file and put the result in a Boot Services Only variable. This allows shim to detect any change of the file made outside of Boot Services and thus avoid tampering with the list of user-approved MOKs. Users with local access can manually enroll keys for items they trust in the Linux (suse) boot process. This is a localized version of the KEK/db system used for the UEFI Certificate Authority (UEFI CA). By relying on the signed shim loader, platform owners can self-sign a custom Linux kernel or kernel drivers without going through the UEFI CA process. Further details available on www.rodsbooks.com/refind/secureboot.html Q8.B Explain in detail how to make USB bootable with any open source tool / utility? Ans.  UNetbootin allows you to create bootable Live USB drives for Ubuntu and other Linux distributions without burning a CD. A Bootable USB" is an AskVG exclusive free tool which allows you to create bootable USB drive to install Windows Vista, Windows Server 2008, Windows 7 and later operating systems.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 32

[8]

It loads distributions by using an ISO file already downloaded.

Select a target drive (USB Drive or Hard Disk), then reboot once done. Note If USB drive doesn't show up, format it as FAT32.

After rebooting, boot from the USB drive. On PCs, this usually involves pressing a button such as Esc or F12 immediately after turn on computer

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 33

Q9.A Write a short note on: i) Multiprocessor scheduling. iii) Linux scheduling. Ans. 

ii) Real time scheduling.

i) Multiprocessor scheduling :- A multiprocessor, scheduling is two dimensional. While uniprocessor (single), scheduling is one dimensional The scheduler has to decide which process to run and which CPU to run it on. This extra dimension greatly complicates scheduling on multiprocessors.

Another complicating factor is that in some systems, all the processes are unrelated whereas in others they come in groups. An example of the former situation is a timesharing system in which independent users start up independent processes. The processes are unrelated and each one can be scheduled without regard to the other ones. The Solution for above mentioned complication is Using a single data structure for scheduling a multiprocessor. Having a single scheduling data structure used by all CPUs timeshares the CPUs, much as they would be in a uniprocessor system. It also provides automatic load balancing because it can never happen that one CPU is idle while others are overloaded. Two disadvantages of this approach are the potential contention for the scheduling data structure as the numbers of CPUs grows and the usual overhead in doing a context switch when a process blocks for I/O. Space Sharing The other general approach to multiprocessor scheduling can be used when processes are related to one another in some way. Earlier we mentioned the example of parallel make as one case. It also often occurs that a single process creates multiple threads that work together. For our purposes, a job consisting of multiple related processes or a process consisting of multiple kernel threads are essentially the same thing. We will refer to the schedulable entities as threads here, but the material holds for processes as well. Scheduling multiple threads at the same time across multiple CPUs is called space sharing. Iii) Linux scheduling.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 34

[12]

Modern Linux scheduling provides improved support for SMP systems, and a scheduling algorithm that runs in O(1) time as the number of processes increases. • The Linux scheduler is a preemptive priority-based algorithm with two priority ranges - Real time from 0 to 99 and a nice range from 100 to 140. • Unlike Solaris or XP, Linux assigns longer time quantums to higher priority tasks. • A runnable task is considered eligible for execution as long as it has not consumed all the time available in it's time slice. Those tasks are stored in an active array, indexed according to priority. • When a process consumes its time slice, it is moved to an expired array. The tasks priority may be re-assigned as part of the transferal. • When the active array becomes empty, the two arrays are swapped. • These arrays are stored in runqueue structures. On multiprocessor machines, each processor has its own scheduler with its own runqueue. ii) Real time scheduling. Real time systems are defined as those systems in which the correctness of the system depends not only on the logical result of computation, but also on the time at which the results are produced" What is real time scheduling ? Many real time systems are built with operating systems providing multitasking facilities, in order to: • Ease the design of complex systems (one function = one task). • Increase efficiency (I/O operations, multi-processor architecture). but the use of task scheduling implies that task schedulers must: Stay predictable Take urgency/criticality task constraints into account. Example of a processor embedded into a car, which is composed of the following tasks: 1. A task displays every 100 milliseconds the current speed of the car. 2. A task reads a speed sensor every 250 milliseconds. 3. A task runs an engine monitoring program every 500 millisec

The real time scheduling theory is a framework which provides : 1. Algorithms to share a processor :- (or any resource) by a set of tasks (or any resource users) according to some timing requirements ⇒ take urgency/criticality of the tasks into account. 2.Analytical methods:- called feasibility tests or schedulability tests , which allow a system designer to analyze/"compute" the system behavior before execution time.

Q9.B Write short notes on: Fail soft operation. Ans.  Definition of real-time system “A real time system is one in which the correctness of the computation not only depends on the logical correctness of the computation, but also on the time at which the result is computed. If the timing constraints of the system are not met, system failure is said to have occurred” ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 35

[6]

Tasks or processes attempt to control or react to external events occurring in “real time” RT processes must be able to keep up events Hard Real Time: timing violation produces a disaster Soft Real Time: timing violation is undesirable but not catastrophic Fail-soft operation is referred to as stability. A realtime system is stable if, in cases where it is impossible to meet all task deadlines, the system will meet the deadlines of its most critical, highest-priority tasks, even if some less critical task deadlines are not always met. Fail-soft operation is a characteristic that refers to the ability of a system to fail in such a way as to preserve as much capability and data as possible. For example, a typical traditional UNIX system, when it detects a corruption of data within the kernel, issues a failure message on the system console, dumps the memory contents to disk for later failure analysis, and terminates execution of the system.

Deadlines In a non real-time system the time by which a task is completed does not influence the overall value or quality – of the system. The value of function shown above . Thus from figure it is clear that Hard-RT tasks have “absolute” priority. OR Q10.A Write a short note on: i) Palm OS. ii) Google Android.

iii) Windows Mobile.

Ans.  1) Palm OS :- Palm OS (also known as Garnet OS) is a mobile operating system initially developed by Palm, Inc., for personal digital assistants (PDAs) in 1996. Palm OS was designed for ease of use with a touchscreen-based graphical user interface. It is provided with a suite of basic applications for personal information management. Later versions of the OS have been extended to support smartphones. Several other licensees have manufactured devices powered by Palm OS. The key features of the Palm OS Garnet are:

• • • • • • • •

Simple, single-tasking environment to allow launching of full screen applications with a basic, common GUI set Monochrome or color screens with resolutions up to 480x320 pixel Handwriting recognition input system called Graffiti 2 HotSync technology for data synchronization with desktop computers Sound playback and record capabilities Simple security model: Device can be locked by password, arbitrary application records can be made private TCP/IP network access Serial port/USB, infrared, Bluetooth and Wi-Fi connections

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 36

[12]

Expansion memory card support Defined standard data format for personal information management applications to store calendar, address, task and note entries, accessible by third-party applications. The recent versions of Palm OS are Palm OS 5 (Garnet) Palm OS Cobalt • •

Palm OS Cobalt introduced modern operating system features to an embedded operating system based on a new kernel with multitasking and memory protection, a modern multimedia and graphic framework, new security features, and adjustments of the PIM file formats to better cooperate with Microsoft Outlook. It also presented standard communication libraries for telecommunication, Wi-Fi, and Bluetooth connectivity. Palm OS Cobalt adds a standard interface for external file system access (such as SD cards). External file systems are a radical change to the operating system's previous in-place execution. Now, application code and data need to be loaded into the device's RAM, similar to desktop operating system behavior. A new Universal Connector with USB support is introduced. The previous optional Mobile Internet Kit is now part of the operating system. Cobalt Version adds an attention manager to coordinate information from different applications, with several possibilities to get the user's attention, including sound, LED blinking or vibration. 16-bit color screens and different time zones are supported. This version also has security and UI enhancements. 2) Android OS :- Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets. Android's user interface is mainly based on direct manipulation, using touch gestures that loosely correspond to real-world actions, such as swiping, tapping and pinching, to manipulate on-screen objects, along with a virtual keyboard for text input. Initially developed by Android, Inc., which Google bought in 2005,Android was unveiled in 2007 along with the founding of the Open Handset Alliance – a consortium of hardware, software, and telecommunication companies devoted to advancing open standards for mobile devices. Android's source code is released by Google under open source licenses, although most Android devices ultimately ship with a combination of open source and proprietary software. Android is popular with technology companies that require a ready-made, low-cost and customizable operating system for high-tech devices. Its open nature has encouraged a large community of developers and enthusiasts to use the opensource code as a foundation for community-driven projects, Android's kernel is based on one of the Linux kernel's long-term support (LTS) [long term support] branches , mainly use versions 3.4, 3.10 or 3.18 of the Linux kernel. Android's variant of the Linux kernel has further architectural changes that are implemented by Google outside the typical Linux kernel development cycle, such as the inclusion of components like Binder, ashmem (Android shared memory ), pmem (Process memory allocator), logger, wakelocks [used for power management files kerne], and different out-of-memory (OOM) handling. Certain features that Google contributed back to the Linux kernel, notably a power management feature called "wakelocks", were rejected by mainline kernel developers partly. iii) Windows Mobile

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 37

Low-level hardware interaction and boot drivers for the phone, in the form of a board support package (BSP). The BSP is a collection of drivers and support libraries. The core of the BSP is written by the silicon vendor that creates the CPU. OEM [Original Equipment Manufacturer] are responsible for adding the drivers required to support the phone hardware, some of which they write themselves. Meanwhile, the kernel and OS on the layer above the kernel are the system services and programming frameworks that applications use to create the user experiences of the phone. Platform extension plug-ins (PEPs) provide interfaces for platform power management including device power management (DPM), processor power management (PPM), and, starting with Windows 10 the Windows hardware abstraction layer (HAL) by adding a real-time subsystem (RTSS) to Windows that delivers deterministic, hard real-time performance. This component provides the ability for isolation of system resources from Windows by providing RTX64 with the ability to dedicate processors/cores to real-time applications. It maintains interrupt isolation between RTSS and Windows. Except setting up RTSS processors/cores to run in IA-32e mode/64-bit sub-mode, the real-time HAL extension supports high-resolution clocks and timers for RTSS. Unified Extensible Firmware Interface (UEFI) is a specification for a software program that connects a computer's firmware to its operating system (OS). UEFI is expected to eventually replace BIOS. Like BIOS, UEFI is installed at the time of manufacturing and is the first program that runs when a computer is turned on. ESENT (Extensible Storage Engine) API in the Windows SDK.ESENT is used by the Active Directory, Windows Desktop Search, Windows Mail and several other Windows services and a slightly modified version of the code is used by Microsoft Exchange to store all its mailbox data Windows Boot Manager (BOOTMGR) is a small piece of software, that's loaded from the volume boot code, which is part of the volume boot record. BOOTMGR helps Windows operating system start. BOOTMGR eventually executes winload.exe, the system loader used to continue the Windows boot process. Configuration data required for BOOTMGR can be found in the Boot Configuration Data (BCD) store, a registrylike database that replaced the boot.ini file used in older versions of Windows like Windows XP. The BOOTMGR file itself is both read-only and hidden and is located in ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 38

the root directory of the partition marked as Active in Disk Management. On most Windows computers, this partition is labeled as System Reserved and does not have a drive letter.

Q10.B Write a short notes on: Frame of reference. Ans.  Repeated.

Note:- This literature is only for private circulation.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 39

[6]

Matoshri College of Engineering & R. C. Nashik Department of Computer Engineering. Subject :- OPERATING SYSTEM DESIGN. Semester:- 5 Subject I/c :- Mr. Ranjit Gawande. MODEL ANSWER – FOR  NOV DEC 15

Model Ans. Paper for Operating System Design 2012 Pat. Q1.A Explain the race condition in assigning inodes.

[4]

Ans. Q1.B Explain in detail monolithic kernel and micro kernel.

[6]

Ans.

Q2A

Elaborate on the following algorithms in brief (any two). 1) iget 2) ifree 3) namei 4) getblk.

[8]

Ans. Q2B

What is system call ?

[2]

Ans. Q3.A Describe the structure of a regular file with proper diagrammatic representation.

[6]

Ans.  Q3.B What is TLB ? Why it is used ?

[4]

Ans. 

Q4.A Explain the concept of a region. What does the region table entry consists of ?

[4]

Ans.  Q4.B If the Page address stream is {2, 3, 2, 1, 5, 2, 4, 5, 3, 2, 5, 2}, and frame size is 3. Identify the page faults occurred using FIFO, LRU. Ans. 

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 40

[6]

Q5.A Explain IPC mechanisms used in System V.

[8]

Ans.  Repeat Question Q5.B What is socket ? Write and explain an algorithm to transfer data between two computers using socket Ans.  To provide common methods for interprocess communication and to allow use of sophisticated network protocols, the BSD system provides a mechanism known as sockets,some user-level aspects sockets mentioned below.

Fig. Shows Socket Model. The kernel structure consists of three parts: the socket layer, the protocol layer, and the device layer (Figure Shown above ).The socket layer provides the interface between the system calls and the lower layers, the protocol layer contains the protocol modules used for communication (TCP and IP in the figure) , and the device layer contains the device drivers that control the network devices. Processes communicate using the client-server model: a server process listens to a socket, one end point of a two-way communications path, and client processes communicate to the server process over another socket, the other end point of the communications path, which may be on another machine. The kernel maintains internal connections and routes data from client to server. The following algorithm for A Server Process in the UNIX System Domain

#include < sys/types.h> #include main( ) { int sd, ns; char buf [256]; struct sockaddr sockaddr; int fromlen; sd = socket(AF_UNIX, SOCK_STREAM, O); /* bind name - don't include null char in the name */ bind(sd, "sockname", sizeof("sockname") - 1 ) ; listen (sd,1) ; for (;;) ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 41

[8]

{

}

}

ns - accept(sd, &sockaddr, &fromlen) ; if (fork()== O) { /*child */ close(sd); read (ns, buf, sizeof(buf) ) ; printf("server read '%s'\n", buf) ; exit () ; } close(ns) ; }

The server program shown above. The process creates a stream socket in the "UNIX system domain" and binds the name sockname to it. Then it invokes the listen system call to specify the internal queue length for incoming messages and enters a loop, waiting for incoming requests. The accept call sleeps until the underlying protocol notices that a connection request is directed toward the socket with the bound name; then, accept returns a new descriptor for the incoming request. The server process forks a process to communicate with the client process: parent and child processes close their respective descriptors so that they do not interfere with communications traffic of the other process. The child process carries on its conversation with the client process, terminating, in this program , after return from the read system call. The server process loops and waits for another connection request in the accept call.

Q6.A What is semaphore ? Provide solution to producer-consumer problem using semaphore. Ans. 

[8]

Semaphore :- The semaphore system calls allow processes to synchronize execution by doing a set of operations atomically on a set of semaphores . Before the implementation of semaphores, a process would create a lock- file with the wanted to lock a resource: The create would process assume that another creat system call if it fails if the file already exists, and the process had the resource locked . The major disadvantages of this approach are that the process does not know when to try again, and lock files may inadvertently be left behind when the system crashes or is rebooted. Dekker algorithm that describes an implementation of semaphores , integer- valued objects that have two atomic operations defined for them. The semaphore system calls are semget to create and gain access to a set of semaphores, semctl to do various control operations on the set, and semop to manipulate the values of semaphores. Further details available on page number 259 GALVIN

Q6.B Explain in detail shared memory and message passing along with their system calls. Ans.  Repeated Question ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 42

[8]

Processes can communicate directly with each other by sharing parts of their virtual address space and then reading and writing the data stored in the shared memory. The system calls for manipulating shared memory are similar to the system calls for messages. The shmget system call creates a new region of shared memory or returns an existing one, the shmat system call logically attaches all region to the virtual address space of a process, the shmdt system call detaches a region from the virtual address space of a process, and the shmctl system call manipulates various parameters associated with the shared memory. Processes read and write shared memory using the same machine instructions they use to read and write regular memory. After attaching shared memory, it becomes part of the virtual address space of a process, accessible in the same way other virtual addresses are; no system calls are needed to access data in shared memory.

The syntax of the shmget system call is shmid = shmget (key, size, flag) ; where size is the number of bytes in the region. The kernel searches the shared memory table for the given key: if it finds an entry and the permission modes are acceptable, it returns the descriptor for the entry. If it does not find an entry and the user had set the IPC_CREAT flag tp create a new region, the kernel verifies that the size is between system-wide minimum and maximum values and then allocates a region data structure using algorithm al/ocreg (Section 6.5.2) . The kernel saves the permission modes, size, and a pointer to the region tabk entry in the shared memory table (Figure 1 1 .9) and sets a flag there to indicate that no memo,ry is associated with the region. It allocates memory (page tables and so on) for the region only when a process attaches the region to its address space. The kernel also sets a flag on the region table entry to indicate that the region should not be freed when the last process attached to it exits. Thus, data in shared memory remains intact even though no processes include it as part of their virtual address space. A process attaches a shared memory region to its virtual address space with the shmat system call: virtaddr = shmat Gd, addr, flags) ;

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 43

Id, returned by a previous shmget system call, identifies the shared memory region, addr is the virtual address where the user wants to attach the shared memory, and flags specify whether the region is read-only and whether the kernel should round off the userspecified address. The return value, virtaddr, is the virtual address where the kernel attached the region, not necessarily the value requested by the process.

Q7.A What is AWK scripting ? Write an AWK script to print squares of numbers from 1 to 10.

[8]

Ans.  AWK is a programming language designed for text processing and typically used as a data extraction and reporting tool. It is a standard feature of most Unix-like operating systems. Some other programming languages similar to AWK are Tcl, AMPL, Perl, Korn Shell (ksh93, dtksh, tksh), Lua. #!/bin/awk -f BEGIN { # Print the squares from 1 to 10 the first way i=1; while (i <= 10) { printf "The square of ", i, " is ", i*i; i = i+1; } # do it again, using more concise code

optional

for (i=1; i <= 10; i++) { printf "The square of ", i, " is ", i*i; } # now end exit; } Two important patterns are specified by the keywords "BEGIN" and "END". #!/bin/awk -f The script itself can be written in many ways. It can be written in both the C shell (csh/tcsh), and Bourne/Bash/POSIX shell script. A third type of AWK script is a "native' AWK script, where you don't use the shell. You can write the commands in a file, and execute awk -f filename

Q7.B Explain in detail how to make USB bootable with any open source tool/utility ? Ans.  Repeated.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 44

[8]

Q8.A What is secure boot ? State the difference between BIOS and UEFI.

[8]

Ans.  Repeated. Q8.B What is make utility ? Explain it with example. Consider your own makefile.

[8]

Ans.  Repeated. Q9.A Draw and explain Android OS architecture. Ans. 

Android uses Linux 2.6 kernel as the hardware abstraction the essences an OS provide Memory management, process management, IPC. It does not have virtual memory and it is implemented IPC Drivers and architecture support. APPLICATION LIBRARY GNU libs (glibc) is too big and complicated for mobile phones, so Android implements its own special version of libc - Bionic libc which is in smaller size - 200K (glibc is more than 400K) Strip out some complicated C++ features, one of the most significant feature is that it has no C++ exception. It is achieved with very special and small pthread implementation, heavily based on kernel futexes. But Bionic libc does not fully support POSIX and is not compatible with glibc Linux kernel does most of the job. Like Page-based memory management , Virtual address to physical address mapping. Android developer use Java ( DALVIK VM ) . A special Java virtual machine (VM) designed to run with limited system resource , thus Memory efficiency increases. In modern JVM Register machine vs. Stack machine used. As it have fewer instructions, and thus faster execution. Java class files

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 45

[6]

are converted into “.dex” files that Dalvik executes. Actually Java byte-code is converted into Dalvik byte-code during this process. MEMORY EFFICIENCY Efficiency increases due to • Shared constant string pool • Share clean (even some dirty) memory between processes as much as possible “.dex” files are mapped as read-only by mmap() • Memory efficient JIT implementation (Just In Time Compiler) • JIT itself is about 100K • Code cache and supporting data structure takes another 100K for each application Libraries On top of Linux kernel there is a set of libraries including open-source Web browser engine WebKit, well known library libc, SQLite database which is a useful repository for storage and sharing of application data, libraries to play and record audio and video, SSL libraries responsible for Internet security etc. • android.app − Provides access to the application model and is the cornerstone of all Android applications. • android.content − Facilitates content access, publishing and messaging between applications and application components. • android.database − Used to access data published by content providers and includes SQLite database management classes. • android.opengl − A Java interface to the OpenGL ES 3D graphics rendering API. • android.os − Provides applications with access to standard operating system services including messages, system services and inter-process communication. • android.text − Used to render and manipulate text on a device display. • android.view − The fundamental building blocks of application user interfaces. • android.widget − A rich collection of pre-built user interface components such as buttons, labels, list views, layout managers, radio buttons etc. • android.webkit − A set of classes intended to allow web-browsing capabilities to be built into applications. Q9.B Explain static table-driven approach for real time scheduling.

[6]

Ans.  Repeated. Q9.C Write short notes on : 1) Fail soft operation 2) Frame of references.

[6]

Ans.  Repeated.

Q10.A Explain the design issues of multiprocessor scheduling. Ans.  Repeated.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 46

[6]

Q10.B Compare hard, soft and firm real time systems.

[6]

Ans.  Repeated. Q10.C Write a note on handheld devices. List various 08 used for handheld devices. Ans.  Repeated.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 47

[6]

Department of Computer Engineering. Subject :- OPERATING SYSTEM DESIGN. Semester:- 5 Subject I/c :- Mr. Ranjit Gawande. MODEL ANSWER – FOR  INSEM ­AUG­16

Model Ans. Paper for Operating System Design 2012 Pat. Q1.A Explain with neat diagram the importance of buffer cache.

[5]

Ans.

The kernel could read and write directly to and from the disc for all file system accesses,but system response time and throughput would be poor because of the slow disk transfer rate. The kernel therefore 'attempts to minimize the frequency of disk access by keeping a pool of internal data buffers, called the buffer cache Advantages The use of buffers allows uniform disk access Alignment restrictions can be overcome by using buffer cache. Buffer cache can reduce the amount of disk traffic. The buffer algorithms help insure file system integrity Above figure shows buffers on their hash queues: the headers of the hash queues are on the left side of the figure, and the squares on each row are buffers on a hash queue. Thus, squares marked 28, 4, and 64 represent buffers on the hash queue for "blkno 0 mod 4" (block number 0 modulo 4). The dotted lines between the buffers represent the forward and back pointers for the hash queue. Similarly, the figure identifies blocks only by their block number, and it uses a hash function dependent only on a block number;

Q1.B Explain getblock () algorithm. Ans.

Five typical scenarios the kernel may follow in getblk to allocate a buffer for a disk block. 1.The kernel finds the block on its hash queue, and its buffer is free. The kernel cannot find the block on the hash queue, so it allocates a buffer from the free list.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 48

[5]

2.The kernel cannot find the block on the hash queue and, in attempting to allocate a buffer from the free list (as in scenario 2) , finds a buffer on the free list that has been marked .. delayed write. " 3.The kernel must write the .. delayed write" buffer to disk and allocate another buffer. 4.The kernel cannot find the block on the hash queue, and the · free list of buffers is empty. 5. The kernel finds the block on the hash queue, but its buffer is currently busy. algorithm getblk input: file system number block number output: locked buffer that can now be used for block { while (buffer not found) { if (block in hash queue) if (buffer busy) { sleep (event buffer becomes free); continue; } mark buffer busy; remove buffer from free list; return buffer; } else { if (there are no buffers on free list) { sleep (event any buffer becomes free); continue; /* back to while loop */ } remove buffer from free list; if (buffer marked for delayed write) { asynchronous write buffer to disk; continue; /* back to while loop */ } /* scenario 2 -- found a free buffer */ remove buffer from old hash queue; put buffer onto new hash queue; return buffer; } }

Q2A

Explain structure of regular files in Unix System V

Ans.

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 49

[4]

Structure of regular files in Unix System V maintained by keeping the inode structure small, but still allow large files, the table of contents of disk blocks conforms to that shown in above figure. The System V UNIX system runs with 13 entries in the inode table of contents, but the principles are independent of the number of entries. The blocks marked "direct" in the figure contain the numbers of disk blocks that contain real data. The block marked "single indirect" refers to a block that contains a list of direct block numbers. To access the data via the indirect block, the kernel must read the indirect block, find he appropriate direct block entry, and then read the direct block to find the data. The block marked "double indirect" contains a list of indirect block numbers, and the block marked "triple indirect" contains a list of double indirect block numbers. In principle, the method could be extended to support "quadruple indirect locks," "quintuple indirect blocks," and so , but the current structure has sufficed in practice. Assume that a logical block on the file system holds 1 K bytes and that a block number is addressable by a 32 bit (4 byte) integer. Then a block can hold up to 256 block numbers

Q2B

Explain namei algorithm.

Ans.

CONVERSION OF A PATH NAME TO AN INODE The initial access to a file is by its path name, as in the open , chdir (change directory) , or link system calls. Because the kernel works internally with inodes rather than with path names, it converts the path names to inodes to access files. The algorithm namei parses the path name one component at a time, converting each component into an inode based on its name and the directory being searched, and eventually returns the inode of the input path name. Below mentioned algorithm shows the steps. algorithm namei /* convert path name to inode */ input: path name output: locked inode

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 50

[4]

{ if (path name starts from root) working inode = root inode (algorithm iget) ; else working inode = current directory inode (algorithm iget); while (there is more path name) { read next path name component from input; verify that working inode is of directory, access permissions OK; if (working inode is of root and component is " . . ") continue; /* loop back to while */ read directory (working inode) by repeated use of algorithms bmap, bread and brelse; if (component matches an entry in directory (working inode)) { get inode number for matched component; release working inode (algorithm iput); working inode = inode of matched component (algorithm iget); } else /* component not in directory */ return (no inode); } return (working inode); } Namei uses intermediate inodes as it parses a path name; call them working inodes. The inode where the search starts is the first working inode. During each iteration of the namei loop, the kernel makes sure that the working inode is indeed that of a directory. Otherwise, the system would violate the assertion that non-directory files can only be leaf nodes of the file system tree. The process must also have permission to search the directory (read permission is insufficient) . The user , ID of the process must match the owner or group ID of the file, and execute permission must be granted, or the file must allow search to all users. Otherwise the search fails.

Q2.C Write a short notes on Super Block. Ans.  To understand how the kernel assigns inodes and disk blocks. One should need to understand the structure of the super block. The super block consists of the following fields: • the size of the file system, • the number of free blocks in the file system, • a list of free blocks available on the fiie system, • the index of the next free block in the free block list, • the size of the inode list, • the number of free inodes in the file system, • a list_of free inodes in the file system, • the index of the next free inode in the free inode list, • lock fields for the free block and free inode lists, • a flag indicating that the super block has been modified. The kernel periodically writes the super block to disk if it had been modified so that it is consistent with the data in the file system. ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 51

[2]

Q3.A Draw and Explain Process State transition diagram. Ans. 

Following are the set of process states. 1 . The process is executing in user mode. 2. The process is executing in kernel mode. 3. The process is not executing but is ready to run as soon as the kernel schedules it. 4. The process is sleeping and resides in main memory. 5. The process is ready to run, but the swapper (process 0) must swap the process into main memory before the kernel can schedule it to execute. 6. The process is sleeping, and the swapper has swapped the process to secondary storage to make room for other processes in main memory. 7. The process is returning from the kernel to user mode, but the kernel preempts it and does a context switch to schedule another process. The distinction between this state

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 52

[6]

and state 3 ("ready to run") will be brought out shortly. 8 . The process is newly created and is in a transition state; the process exists, but it is not ready to run, nor is it sleeping. This state is the start state for all processes except process 0. 9 . The process executed the exit system call and is in the zombie state. The process no longer exists, but it leaves a record containing an exit code and some timing statistics for its parent process to collect. The zombie state is the final state of a process. The above figure gives the complete process state transition diagram.

Q3.B Explain context of a process. Ans. 

The figure shows Components of the Context of a Process The kernel pushes a context layer when an interrupt occurs, when a process makes a system call, or when a process does a context switch. It pops a context layer when the kernel returns from handling an interrupt, when a process returns to user mode after the kernel completes execution of a system call, or when a process does a context switch. The context switch thus entails a push and a pop of a system-level context layer: The kernel pushes the context layer at the old process and -pops the context layer of the new process. The process table entry stores the necessary information to recover the current context layer. The above figure depicts the components that form the context of a process. The left side of the figure shows the static portion of the context. It consists of the user level context, containing the process text (instructions), data, stack, and shared memory ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 53

[4]

(if the process has any), and the static part of the system-level context, containing the process table entry, the u area, and the pregion entries (the virtual address mapping information for the user-level context). The right side of the figure shows the dynamic portion of the context. It consists of several stack frames, where each frame contains the saved register context of the previous layer, and the kernel stack as the kernel executes in that layer. System context layer 0 is a dummy layer that represents the user-level context; growth of the stack here is in the user address space, and the kernel stack is null. The arrow pointing from the static part of the system-level context to the top layer of the dynamic portion of the context represents the logical information stored in the process table entry to enable the kernel to recover the current context layer of the process .

Q4.A Solve the following by Bankers Algorithm Allocation Matrix Max Claim Matrix ABCD ABCD P0 0110 0210 p1 1231 1652 p2 1365 2366 p3 0632 0652 p4 0014 0656

[4] Total Resources. ABCD 3 17 16 12

create the need matrix Use the safety algrorithm to test if the system is in a safe state. Ans. 

Max Claim Matrix A B C D 0 2 1 0 1 6 5 2 2 3 6 6 0 6 5 2 0 6 5 6

Allocation A B C D 0 1 1 0 1 2 3 1 1 0 6 1 0 6 3 2 0 0 1 4

Total Resources. A B C D 3 17 16 12 Available A B C D 1 5 2 0

Needs P0 P1 P2 P3 P4

A 0 0 1 0 0

B C D 1 0 0 4 2 1 0 0 1 0 2 0 6 4 2

Updated Available P0 P3 P1 P2 P4

A B C D 1 6 3 0 1 12 6 2 2 14 9 3 3 17 15 8 3 17 16 12

Valid Sequences 1) P0 = P3 ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 54

P1 = P2 -P4 2) P0 = P3 P4 = P1 -P2 3) P0 = P3 Q4.B

[6]

Ans.  Q5.A

[8]

Ans.  Q5.B

[8]

Ans. 

Q6.A

[8]

Ans.  Q6.B

[8]

Ans. 

Q7.A

[8]

Ans.  Q7.B

[8]

Ans. 

Q8.A

[8]

Ans.  Q8.B Ans. 

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 55

[8]

Q9.A

[6]

Ans.  Q9.B

[6]

Ans.  Q9.C

[6]

Ans. 

Q10.A

[6]

Ans.  Q10.B

[6]

Ans.  Q10.C Ans. 

______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Department of Computer Engineering M.C.E.R.C. Nashik. T. E. Computer Engineering Sem – 5 Subject:- Operating System Design Page no 56

[6]

Operating System Design Solved Question Papers SPPU TE COMP ...

A Explain in short - BIOS, MBR and init( ) process. [6]. Ans. The stages involved in Linux Booting Process are: 1) BIOS 2) Boot Loader ... MBR directly cannot load the kernel as it is unaware of the filesystem concept. and requires a .... Operating System Design Solved Question Papers SPPU TE COMP.pdf. Operating System ...

2MB Sizes 2 Downloads 175 Views

Recommend Documents

Operating System Design Solved Question Papers SPPU TE COMP ...
MBR directly cannot load the kernel as it is unaware of the filesystem concept. and requires a boot loader with file system driver for each supported file systems, ...

Question Papers CBE.pdf
Page 3 of 5. Question Papers CBE.pdf. Question Papers CBE.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Question Papers CBE.pdf. Page 1 of ...

AIBE Examination Solved Question Paper.pdf
Page 1 of 12. AIBE All India Bar Examination 6 March 2016 Solved Question Paper with Answer key www.Upjob.in. Page 1 of 12. Page 2 of 12. Page 2 of 12. Page 3 of 12. Page 3 of 12. Main menu. Displaying AIBE Examination Solved Question Paper.pdf. Page

Clerical Attender Solved Question
(e) Boulder. 22. Which is the closest Planet to Sun? (a) Mercury ... Name the first Indian who won Nobel Prize in Physics. (a) S. Chandrasekhar. (b) C.V. Raman.

Solved Question Paper 4.pdf
... precedence of arithmetic operators can be given from two distinct levels, they are ... Eg: suppose a is declared as integer. The size of a is. Int a;. x = size of (a); ... at “size of array-1” for example consider the array. int a[5]. here th

Solved Question Paper Plane Geometry_Dececmber 2016.pdf ...
Page 1 of 17. Page 1 of 17. devsamajcollege.blogspot.in Sanjay Gupta, Dev Samaj College For Women, Ferozepur City. SOLVED QUESTION PAPER PLANE GEOMETRY_DECEMBER 2016. B.A. / B.Sc. 1st SEMESTER, P.U. ( PAPER - I ). Q.1(a). Q.1(b). Page 1 of 17 ...

PDF Download Design of the UNIX Operating System
... J. Bach traces the popularity of the UNIX system throughout the computer ... kernel architecture Introduces the system buffer cache mechanism Includes data ... interface to the file system Defines the context of a process and investigates the ...