Sei sulla pagina 1di 4

Solved Answers by Yagnesh Find me on facebook yagnesh_shenoy@yahoo.co.

in if you have any doubts u can contact me I dont guarantee the answers are correct , use this at your own risk

Question 1: Explain the three main purposes of an operating system? What is layered approach to OS design? Also, describe its advantages and disadvantages. Answer
An Operating System is a system software which may be viewed as an organised collection of software consisting of procedures for operating a computer and providing an environment for execution ofprograms. It acts as an interface betwcen users and the hardware of a computer system. The 3 important reasons for studying operating systems are: (1) User interacts with the computer through operating system in order to accomplish his task since it is his primary interface with a computer. (2) It helps users to understand the inner functions of a computer very closely. (3) Many concepts and techniques found in operating system have general applicability in other applications.

Layered Structure Approach The operating system architecturebased on layered approach consists of number of layers (levels), each built on top of lower layers. The bottom layer is the hardware: the highest layer is the user interface. The first system constructed in this way was the THE system built by E.W. Dijkestra (1968) and his students. The THE system was a simple batch operating system which had 32k of 27 bit words.

As shown in figure 7, layer 0 dealt with hardware; the higher layer layer1 'handled allocation of jobs to processor. The next layer implemented memory management. The memory management scheme was virtual memory (to be discussed in Unit 3). Level 3 contained the device driver for the operator's console. By placing it, as well as 110 buffering at level 4, above memory management, the device buffers could be placed in virtual memory. The 40 buffering was also above the operator's console, so that I10 error conditions could be output to the operator's console. Advantages The main advantage of the layered approach is modularity which helps in debugging and verification of the system easily. The layers are designed in such a way that it uses operation and services only if a layer below it. A higher layer need not know how thcse operations are implemented, only what these operation do. Hence each layer hides implcmentation derails from higher level layers. Ady layer can be debugged without any

concern about the rest ofthe layer. Disadvantages The major difficulty with the layered approach is definition of a new level i.e. how to differentiate one level from another. Since a layer can use services of a layer below it, it should be designed carefully. For example, the device driver for secondary memory must be at a lower level than the memory management routines since memory management requires the ability to use the backing store.

Question 2: Write a shell program to generate the first 25 prime numbers. Answer echo enter a range read rng echo 2 j=3 while test $j -le $rng do i=2 x=`expr $j - 1` while test $i -le $x do if [ `expr $j % $i` -ne 0 ] then i=`expr $i + 1` else break fi done if [ $i -eq $j ] then echo $j fi j=`expr $j + 1` done

Question 3:

What is Mutual Exclusion? Write pseudo code to implement mutual exclusion using: (i) Test and Set instruction and (ii) Swap instruction

Answer A critical section is a piece of code in which a process or thread accesses a common

resource. The critical section by itself is not a mechanism or algorithm for mutual exclusion. A program, process, or thread can have the critical section in it without any mechanism or algorithm which implements mutual exclusion.

Test and Set instruction In pseudo C it would be like:


volatile int lock = 0; void Critical() { while (TestAndSet(&lock) == 1); critical section //only one process can be in this section at a time lock = 0 //release lock when finished with the critical section }

Swap instruction int compare_and_swap ( int* reg, int oldval, int newval)
{ int old_reg_val = *reg; if (old_reg_val == oldval) *reg = newval; return old_reg_val; }

Question 4:

Consider the following set of processes: Process P1 P2 P3 P4 P5 Burst time (ms) 10 29 3 7 12

Evaluate the performance of FCFS, SJF and RR (Quantum = 10 ms) algorithms for scheduling the above processes.

Answer

Solve this Yourself zuhahahahahahahhaha No seriously its difficult answer I dont have time to type it

Question 5:

Write a shell program to cipher all the text/content in any text document in the current working directory and also use another shell program to decipher it to read. Use any scheme for ciphering.

Answer Encrypting #!/bin/bash openssl des3 -d -salt -in cipher.txt -out plain.txt Deciphering #!/bin/sh
while read inputline do login="$(echo $inputline | cut -d: -f1)" fulln="$(echo $inputline | cut -d: -f4)" echo login = $login and fullname = $fulln done < /etc/passwd exit 0

Question 6: Write the UNIX commands for the following tasks: 1 find lines common to two or more files answer : comm.filename1.filename2 2 compare files but stops at first occurrence of a difference answer: grep mystring myfile 3 show differences of two files answer: diff file1 file2 4 list all jobs in the waiting queue

answer: ps -ef

Potrebbero piacerti anche