Sunday, December 9, 2012

::::|| VU ||:::: CS502- MID TERM SUBJECTIVE WITH REFERENCE SOLVED BY UMAIR SAULAT

CS502  - Fundamental of Algorithm

Short- Question Answer  for MID TERM

 

QNo.1  What is heap and what is heap order? (Mark2)

Answer:-

The heap is the section of computer memory where all the variables created or initialized at runtime are stored.  The heap order property: in a

(min) heap, for every node X, the key in the parent is smaller than or equal to the key in X.

Ref:  Handouts Page no. 40

 

 

QNo.2  Quick sort such that sort the array in to non-increasing order? (Mark2)

Answer:-

 

Quick sorting, an array A[1..n] of n  numbers We are to reorder these elements into increasing (or decreasing) order.  More generally, A is an array of objects and we sort them based on one of the attributes - the key value. The key value need not be a number. It can be any object from a totally ordered domain. Totally ordered domain means that for any two elements of the domain, x and y, either x < y, x = y or x > y.

Ref:  Handouts Page no. 40

 

 

QNo.3  Draw the cost table for chain multiplication problem with initial states(Mark3)

Answer:-

 (A1)(A2A3A4 . . .An)

or (A1A2)(A3A4 . . .An)

or (A1A2A3)(A4 . . .An)

. . . . . .

or (A1A2A3A4 . . .An−1)(An)

Ref:  Handouts Page no. 90

 

QNo.4  we can avoid unnecessary repetitions for recursive calls? (Mark3)

Answer:-

We can avoid these unnecessary repetitions by writing down the results of recursive calls and looking them up again if we need them later. This process is called memorization

Ref:  Handouts Page no. 49

 

Worst case for edit distance algorithm? What is the simple change that can change the worst case time ? 5 marks

Answer:-

Analysis of DP edit distance

There are  entries in the matrix. Each entry E(i,j) takes  time to compute. The total running is  Recursion clearly leads to the same repetitive call pattern that we saw in Fibonnaci sequence. To avoid this, we will  use the DP approach. We will build the solutionb bottom-up. We will use the base case E(0,j) to fill first row and the base case E(I,0) to fill first column. We will fill the remaining E matrix row by row.

 

Ref:  Handouts Page no. 14

 

 

Describe an efficient algorithm to find the median of a set of 106 integers; it is known that there are fewer than 100 distinct integers in the set

 

Solution:-

Step1:Start

Step2:Find the 100 distinct numbers among 10^6 integers.

Step3:Sort the 100 distinct numbers

Step4:Count the distinct numbers

Step5: if count is odd,middle number is the median

Step6:if count is even,add the middle two numbers then divide by 2,the result is the median Step5:End

number.

 

Ref:  Handouts Page no. 34

 

What is the formula for generating Catalan numbers?

Solution

Equation (22) is a recurrence relation.
C_(n+1) = C_n * [2(2n+1)] / (n+2)

we have the values of n in one column and the values of C_n in another, then to put this formula in Excel, on the (n+1)-th row just replace C_n and n with the appropriate cells from the previous row.

Ref:  Handouts Page no. 85

 

What are Catalan numbers? Give the formula.

 

Catalan numbers form a sequence of natural numbers that occur in variouscounting problems, often involving recursively defined objects

Formula is C(n) = 2n Cn / (n+1)

Ref:  Handouts Page no. 85

 

 

 

Q-Write a pseudo code Fibonacci With memorization? -- (3)

Sol
MEMOFIB(n)
1 if (n < 2)
2 then return n
3 if (F[n] is undefined)
4 then F[n] MEMOFIB(n − 1) + MEMOFIB(n − 2)
5 return F[n]

Ref:  Handouts Page no. 12, 74


Q – Write Down the steps of Dynamic programming (5)

Dynamic programming is essentially recursion without repetition. Developing a dynamic programming
algorithm generally involves two separate steps:

 

·         Formulate problem recursively. Write down a formula for the whole problem as a simple
combination of answers to smaller sub problems.

·         Build solution to recurrence from bottom up. Write an algorithm that starts with base cases and works its way up to the final solution.


Dynamic programming algorithms need to store the results of intermediate sub problems. This is often but not always done with some kind of table. We will now cover a number of examples of problems in which the solution is based on dynamic programming strategy.

Ref:  Handouts Page no. 74 – 77

 

 

How we build heap

We build a max heap out of the given array of numbers A[1..n]. We repeatedly extract the maximum item from the heap. Once the max item is removed, we are left with a hole at the root.

Ref:  Handouts Page no. 41

 

Write Pseudo code for KNAPSACK algorithm? 5 marks

Solution:

KNAPSACK (n, W)

1 for w=0,W

2 do V[0,w]ß0

3 for i=0,n

4 do V[i,0]ß0

5   for w=0,W

6   do if(wi w&  +V[i-1,w- ]>V[i-1,w])

7                      then V[I,w]ß +V[i-1,w]


8                      else V[i,w]
ßV[i-1,w]

The time complexity is clearly O(n,W), it must be cautioned that as n and W get large, both time and space complexity become significant.

Ref:  Handouts Page no. 96

 

 

Spelling correction in edit distance? 3 marks

A better way to display this editing process is to place the words above the other:

S  D  I  M  D  M

 M A  -   T  H  S

  A  -   R  T  -  S

THE FIRST WORD HAS AGAP FOR EVERY INSERTION (1)AND THE SECOND WORD HAS A GAP FOR EVERY DELETION (D). MATHES (M) DO NOT COUNT. THE EDIT TRANSCRIPT IS DEFINED AS A STRING OVER THE ALPHABETM,S,I,d THAT DESCRIBES A TRANSFORMATION OF ONE STRING INTO OTHER. FOR EXAMPLE

S D I M D M

1+1+1+0+1+0+=4
Ref:  Handouts Page no. 77


Differentiate b/w Bubble sort, insertion sort and selection sort? 3 marks

 

SOLUTION:

Bubble sort: scan the array. Whenever two consecutive items are found that are out of order, swap them. Repeat until all consecutive items are in order.

Insertion sort: assume that A[1…i-1] have already been sorted. Insert A[i] into its proper position in this sub array. Create this position by shifting all larger elements to the right.

Selection sort:

Assume that A[1..i-1] contain the i-1 smallest elements in sorted order. Find the smallest in A[i….n] swap it with A[i].

Ref:  Handouts Page no. 54

 

Write down the steps of dynamic programming strategy.   (2 marks)

Solution:

Developing a dynamic programming algorithm generally involves two separate steps:

1_formulate problem recursively.

Write down a formula for the whole problem as a simple combination of answers to smaller sub problems.

2_ Build solution to recurrence from bottom up:

Ref:  Handouts Page no. 75

 

Solve the recursion problem. (5marks.)

Solution:

Recursion clearly leads to the same repetitive call pattern that we saw in Fibonnaci sequence. To avoid this, we will  use the DP approach. We will build the solutionb bottom-up. We will use the base case E(0,j) to fill first row and the base case E(I,0) to fill first column. We will fill the remaining E matrix row by row.

If we trace through the recursive calls to MemoFib, we find that array F[] gets filled from bottom up…i.e., first  F[2], then F[3], and so on, upto F[n]. we can replace recursion with a simple for-loop that just fills up the array F[] in that order.

                                                                      
•       We are given an array of n elements of x1 , x2 ,x3 , ,,,,xn,
suggest best sorting algorithm of order On.  (5 marks).

Solution:

The main shortcoming of counting sort is that it is useful for small integers, i.e., 1…k where k is small. If this were a million more, the size of the rank array would also be a million. Radix sort provides a nice work around this limitation by sorting numbers one digit at a time.

2012

 

What are the two steps generally involved while developing dynamic programming algorithm.    (2)

Solution:

Developing a dynamic programming algorithm generally involves two separate steps:

• Formulate problem recursively.

Write down a formula for the whole problem as a simple

combination of answers to smaller subproblems.

• Build solution to recurrence from bottom up.

Write an algorithm that starts with base cases and works its way up to the final solution.

Ref:  Handouts Page no. 75

 

How we build heap? (2)

Solution:

We build a max heap out of the given array of numbers A[1..n]. We repeatedly extract the maximum item from the heap. Once the max item is removed, we are left with a hole at the root.

Ref:  Handouts Page no. 41

 

What are the applications of edit distance technique? Name any three (3)

Solution:

Spelling Correction

Plagiarism Detection

Computational Molecular Biology

Ref:  Handouts Page no. 76

 

Solve: T(n) =  (T(q − 1) + T(2 − q) + 2)                                                              (3)

What is the worst case running time for the bucket sort? What simple change is required in the algorithm to preserve its linear expected running time and makes it worst case time Θ(n log n)  (5)

Solution:

The worst case for bucket sort occurs when the all inputs falls into single bucket,

for example. Since we use insertion sort for sorting buckets and insertion sort

has a worst case of O(n2). the worst case runtime for bucket sort is O(n2).

 

By using an algorithm with worst case runtime of O(nlgn) instead of insertion sort for sorting buckets, we can ensure that worst case is O(nlgn) without affecting the average case behavior.

 

To see that the worst case is still O(nlgn), lets consider a case where n data are distributed among two buckets, a elements in one bucket and na in the other. Since we use O(nlgn sorting algorithm in each bucket, the run time for each sort is, kalg(a) + c2 and k(n  a)lg(n  a) + c2, where k; c2 are positive constants. The total runtime is kalg(a)+k(na)lg(na)+2c2 This quantity attains its maximum value when a = 0 or a = n and the maximum value is knlgn + 2c2. Thus total runtime is still O(nlgn). It is clear from

this that maximum running cost occurs when data are in single bucket instead

of spread in two buckets. Extending this argument, we can see that worst case

for the hash table occurs when all inputs hash into the same bucket. (We also

note that the expressions obtained are basically convex combinations of nlgn

which is a convex function and then jensen's rule can be applied to arrive at the

same conclusion).

Ref:  http://classes.soe.ucsc.edu/cmps101/Spring11/hw/hw3sol.pdf

 

Given an unordered list of n x0, x1, x2, …, xn and elements is common, if there are atleast n/5 copies of it.We want to identify all the common numbers in our list. Give O(n log n) to solve the problem. (5)

Solution:

We define R n to be the set of ordered n-tuples of real numbers,

Rn := {(x1, x2 . . . xn) : x1, . . . , xn R}.The elements of Rn are called vectors. Given a vector x = (x1, . . . , xn), the numbers x1, . . . , xn are called the components of x.

You are already quite familiar with Rnfor small values of n.

Ref:  http://www.math.rice.edu/~hassett/teaching/221fall05/linalg1.pdf

 

Find the out cost A1=5 x 4 A2= 4 x 6  A3= 6x2 (2 marks)

Solution:-

For Instance

A1.       =          5          x          4

A2        =          4          x          6

A3        =          6          X          2

 

And A4 =          2          x          7

Hence

A1 x (A2 A3) XA4 = ((5 X 4 X 2 ) + (4 X 6  2)) + 2 X 7 X 5

= 40     +          48        + 70

=  88    +          70

= 158

HERE OPTIMAL SEQUENCE IS A1 (A2 A3) A4. For this cost 158 which is optimal the optimal sequence is a1x (a2 xa3) xa4

REF:: http://books.google.com.pk/books?id=9mBJ0CpKXdkC&pg=SA11-PA37&lpg=SA11-PA37&dq=Find+the+out+cost+A1%3D5+x+4++A2%3D+4+x+6++A3%3D+6x2&source=bl&ots=xYZLnJv6zx&sig=C_u-HLVZ-iQCjvwNpG2hhkosCf4&hl=en&sa=X&ei=i_TEUInCMJOyhAffyoDYAw&redir_esc=y#v=onepage&q=Find%20the%20out%20cost%20A1%3D5%20x%204%20%20A2%3D%204%20x%206%20%20A3%3D%206x2&f=false

 

 

How to construct an optimal solution for o/1 knapsack problem ?

Construction of optimal solution: Construct an optimal solution from computed information. Let us try this: If items are labelled 1, 2, . . . , n, then a subproblem would be to find an optimal solution for S k = items labelled 1, 2, . . . , k This is a valid subproblem definition. The question is: can we describe the final solution S n in terms of

subproblems S k ? Unfortunately, we cannot do that. Here is why. Consider the optimal solution if we can choose items 1 through 4 only.

Solution

Items chosen are 1, 2, 3, 4

Total weight: 2 + 3 + 4 + 5 = 14

Total value: 3 + 4 + 5 + 8 = 20

Now consider the optimal solution when items 1 through 5 are available

Ref:  Handouts Page no. 92

 

Effect of calling max heap

Solution:-

The smallest key is in the root in a min heap; in the max heap, the largest is in the root.

Ref:  Handouts Page no. 40

 

 

 

Suggest the criteria for measuring algorithms. Also discuss the issues need to be

discussed in the algorithm design.

Solutions:-

In order to design good algorithms, we must first agree the criteria for measuring algorithms. The emphasis in this course will be on the design of efficient algorithm, and hence we will measure algorithms in terms of the amount of computational resources that the algorithm requires. These resources include mostly running time and memory. Depending on the application, there may be other elements that are taken into account, such as the number disk accesses in a database program or the communication bandwidth in a networking application.

Ref:  Handouts Page no. 9


--
Zindagi mein 2 Logo ka buhat khayal rahkoooo
Ist woh jiss ney tumhari jeet ke Liye buhat kuch hara hoo
(Father)
2nd woh jiss ko tum ney har dukh me pukaara hoo (Mother)
Regards,
Umair Saulat Mc100403250

--
--
For study materials, past papers and assignments,
Join VU School at www.vuscool.com
 
Facebook Group link
http://www.facebook.com/groups/vuCoooL
 
CoooL Virtual University Students Google Group.
To post to this group, send email to coool_vu_students@googlegroups.com
 
home page
http://groups.google.com/group/coool_vu_students?hl=en
 
 
 

::::|| VU ||:::: Recent Latest Papers

Assalm-u-Alaikum

All recent latest papers shared by students.

--
--
For study materials, past papers and assignments,
Join VU School at www.vuscool.com
 
Facebook Group link
http://www.facebook.com/groups/vuCoooL
 
CoooL Virtual University Students Google Group.
To post to this group, send email to coool_vu_students@googlegroups.com
 
home page
http://groups.google.com/group/coool_vu_students?hl=en
 
 
 

::::|| VU ||:::: CS604 MID TERM SUBJECTIVE WITH REFERENCE SOLVED BY UMAR SAULAT

CS604- OPERATING SYSTEM

SOLVED SUBJECTIVE FOR MID TERM EXAM

 

 QNo.1 List and define the different metrics by which might evaluate a scheduler (List at least 4). 5 marks

Answer:-

When evaluating a scheduler's performance, utilization and Throughput are traded off for better Response Time. Response time is important for OS's that aim to be user-friendly.

List of Schedulers include:

  1. First-Come, First-Served  (FCFS)
  2. Round-Robin   (RR)
  3. Shortest-Job-First  (SJF)
  4. Priority Scheduling  (PS)

REF :: handouts Page No. 80

 

QNo.2   Write brief the multilevel feedback queue scheduling. 5 marks

Answer:-

Multilevel feedback queue scheduling allows a process to move between queues. The idea is to separate processes with different CPU burst characteristics. If a process uses too much CPU time, it will be moved to a lower-priority queue. This scheme leaves I/O bound and interactive processes in the higher-priority queues. Similarly a process that waits too long in a lower-priority queue may be moved o a higher priority queue. This form of aging prevents starvation.

 

In general, a multi-level feedback queue scheduler is defined by the following parameters:

  • Number of queues
  • Scheduling algorithm for each queue
  • Method used to determine when to upgrade a process to higher priority queue
  • Method used to determine when to demote a process
  • Method used to determine which queue a process enters when it needs service

REF :: handouts Page No. 89

 

Qno.3    Assumption made while formulating a solution to the critical section problem. 2 marks

Answer:-

A solution to the critical section problem must satisfy the following three requirements:

Assumptions made While formulating a solution, we must keep the following assumptions in mind:

  • Assume that each process executes at a nonzero speed
  • No assumption can be made regarding the relative speeds of the N processes.

REF :: handouts Page No. 98


Qno.4    There are many commands. Write the method through which these commands can communicate with each other. 3 marks

Answer:-

There are many commands some of these are given below:-

Command Name              $ pw

Details

You can display the absolute pathname of your working directory with the pwd command

Syntax

/home/students/nadeem/courses/cs604/programs

 

Command Name              cp

Details

You can use the cp command for copying files. You can use the cp file1

file2 command to copy file1 to file2.

Syntax

 cp ~/file1 ~/memos/file2

 

Command Name              mv

Details

You can use the mv command for moving files. You can use the mv file1

file2 command to move file1 to file2.

Syntax

$ mv ~/file1 ~/memos/file2

 

Command Name              rm

Details

You can use the rm command to remove files. You can use the rm file1

command to remove file1

Syntax

$ rm ~/courses/cs604/programs/test.c $               For single file

rm *.o                                                                                   For all files                        

REF :: handouts Page No. 27

 

Qno.5. Write Difference between SJF and Shortest Remaining Time First Scheduling algorithm. 3 marks

Answer: 

Shorted Job First (SJF) Scheduling

Shortest Remaining Time First Scheduling

For long term scheduling in a batch system, we can use as the length the process time limit that a user specifies when he submits the job

Whenever a new job comes in, check the remaining service time on the

current job.

Preemptive SJF scheduling is sometimes called shortest-remaining-time-first scheduling.

For all but the longest jobs, SRT better than SJF

The response ratio is good (Fast)

The response ratio is good (low)

Waiting time is fast

Waiting time is also quite low for most processes

REF :: handouts Page No. 82

Qno6.    Write formula for calculating waiting time in preemptive Shortest Job First Algorithm. 2 marks

Answer:-

Preemptive SJF scheduling is sometimes called shortest-remaining-time-first scheduling.

We illustrate the working of the SJF algorithm by using the following system state.

 

Process       Arrival Time   Burst Time

P1           0.0          7

P2           2.0          4

P3           4.0          1

P4           5.0          4

REF :: handouts Page No. 83

 

Qno7.    Define race condition and how prevent this condition. 2 marks

Answer:-

A situation like this, where several processes access and manipulate the same data
concurrently and the outcome of the manipulation depends on the particular order in
which the access takes place, is called a race condition

REF :: handouts Page No. 97

 

Qno.8    What is Convoy Effect?
Answer:-

When FCFS scheduling algorithm is used, the convoy effect occurs when short

Processes wait behind a long process to use the CPU and enter the ready queue in a

Convoy after completing their I/O.

REF :: handouts Page No. 82


Qno.9    What are the common data structures in Bakery Algorithm?
Answer:-

The bakery algorithm is due to Leslie Lamport and is based on a scheduling algorithm

commonly used in bakeries, ice-cream stores.

REF :: handouts Page No. 103

 

Qno.10 How a pipe can be created?
Answer:-

The pipe() system call   creates a   pipe and returns two file descriptors, one for reading and second for writing,

REF :: handouts Page No. 103

 

Qno.11 Define Progress and Bounded Waiting.
Answer:-

Process:-

If no process is executing in its critical section and some processes wish to enter their critical sections, then only those processes that are not executing in their remainder section can participate in the decision on which will enter its critical section next, and this selection cannot be postponed indefinitely.

 

 

Bounded Waiting:-

There exists a bound on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted.

REF :: handouts Page No. 99

 

Qno.12 What is Starvation and how it occures
Answer:-

Starvation:-

A process that is ready to run but lacking the CPU can be considered blocked-waiting for the CPU.

How it occur:-  

If a deadlock occurs, it can be resolved if one car backs up (preempt resources
and rollback). Several cars may have to be backed up if a deadlock occurs. Starvation is
possible.

REF :: handouts Page No. 129

 


Qno.13 What are the advantages of Round Robin Scheduling Algorithm?
Answer:-

  • If time slice is too short then you will have freq switching btw processes
  • if time slice is too long then you will have less switching btw processes and high priority may have to wait for low priority tasks leading to starvation
  • The average waiting time under the RR policy however is often quite long.
  • The CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval of up to 1 time quantum
  • The process may have a CPU burst of less than 1 time quantum, in which case the process itself will release the CPU voluntarily.
  • It is the most simple scheduling algorithm
  • It is easy to implement in software
  • If the processes are of varied length then it becomes slow.

REF :: handouts Page No. 86


Qno.14 Analyze the following algorithm to solve the critical section problem and explain whether it satisfies the Mutual Exclusion Characteristic

Flag[i] = True;
Turn = j;
do{
while(Flag[j] = True && turn==j);
critical section
Flag[i] = False;
remainder section
} While(1)


Answer:-

 

To enter its critical section, Pi sets flag[i] to true, and sets 'turn' to j, asserting that if the other process wishes to enter its critical section, it may do so. If both try to enter at the same time, they will attempt to set 'turn' to i and j. However, only one of these assignments will last, the other will occur but be overwritten instantly. Hence, the eventual value of 'turn' will decide which process gets to enter its critical section.

 

To prove mutual exclusion, note that Pi enters its critical section only if either

flag[j]=false or turn=i. Also, if both processes were executing in their critical sections at
the same time, then flag[0]= = flag[1]= = true. These two observations suggest that P0 and
P1 could not have found both conditions in the while statement true at the same time,
since the value of 'turn' can either be 0 or 1. Hence only one process say P0 must have
successfully exited the while statement.  Hence mutual exclusion is preserved.

To prove bounded wait and progress requirements, we note that a process Pi can be
prevented the critical section only if it is stuck in the while loop with the condition
flag[j]= =true and turn=j. If Pj is not ready to enter the critical section, then flag[j]=flase
and Pi can enter its critical section. If Pj has set flag[j]=true and is also executing its while
statement then either turn=i or turn=j. If turn=i then Pi enters its critical section, otherwise
Pj. However, whenever a process finishes executing in its critical section, lets assume Pj,
it resets flag[j] to false allowing Pi to enter its critical section. If Pj resets flag[j]=true, then
it must also set 'turn' to i, and since Pi does not change the value of 'turn' while
executing in its while statement, Pi will enter its critical section (progress) after at most
one entry by Pj (bounded waiting).

REF :: handouts Page No. 145

 

Qno.15 which command is used in Linux environment to get process information? (2)

Answer:-

ps gives a snapshot of the current processes. Without options, ps prints information
about processes owned by the user. Some of the commonly used options are -u, -e, and
-l.

  • -e selects all processes
  • -l formats the output in the long format
  • -u displays the information in user-oriented format

REF :: handouts Page No. 63

 

Qno.16 resource sharing is disadvantage of multithreading....explain?(5)

Answer:-

1.  Resource sharing: Whereas resource sharing is one of the major advantages of
                threads, it is also a disadvantage because proper synchronization is needed
                between threads for accessing the shared resources (e.g., data and files).

2.  Difficult programming model: It is difficult to write, debug, and maintain multi-
                threaded programs for an average user. This is particularly true when it comes to
                writing code for synchronized access to shared resources.

REF :: handouts Page No. 70

Qno.17 Synchronization process is needed in resource sharing and data sharing (3)

Answer:-

Often access to shared data and shared resources, if there is no controlled access to shared data, it is often possible to obtain an inconsistent state of this data. Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes, and hence various process synchronization methods are used.

REF :: handouts Page No. 70


Qno.17 how threads overcome these issues (5)

Answer:-

A thread, sometimes called a lightweight process (LWP), is a basic unit of CPU utilization and executes within the address space of the process that creates it. It comprises a thread ID, a program counter, a register set, errno, and a stack. It shares with other threads belonging to the same process its code sections, data section, current working directory, user and group IDs, signal setup and handlers, PCB and other operating system resources, such as open files and system.

REF :: handouts Page No. 68

 

Qno.18 If process in background then we want its move in foreground then what unix/inux command is use to moving. 3 marks

Answer:-

Moving a process into background

You can use the bg command to put the current or a suspended process into the background. Here is the syntax of the command.

bg [%job_id]

If %job_id is omitted the current job is assumed.

REF :: handouts Page No. 65


Qno.19 How the open source help us to test the algorithm?

Answer:-

The Open Source software licensing has made it possible for us to test various algorithms by implementing them in the Linux kernel and measuring their true performance. The major difficulty is the cost of this approach. The expense is incurred in coding the algorithm and modifying the operating system to support it, as well as its required data structures. The other difficulty with any algorithm evaluation is that the environment in which the algorithm will change.
REF :: handouts Page No. 95

 

 

Qno.20                 Using C for compiling means?

Answer:-

To compile a source file titled program.c, type:
$ gcc program.c

You can run the executable program generated by this command by typing./a.out and
hitting the <Enter> key, as shown in the following session.
$ ./a.out
[ ... program output ... ]

You can store the executable program in a specific file by using the –o option. For
example, in the following session, the executable program is stored in the assignment file.
$ gcc program.c -o assignment

 

You can link a library                   
explicitly by using the –l option. In the following session, we are asking the compiler to
link the math library with our object file as it creates the executable file.
$ gcc program.c –o assignment -lm

$ assignment

[ ... program output ... ]

REF :: handouts Page No. 28


Qno.21 what is difference b/w preemptive and non-preemptive (2)

Answer:-

Preemptive

non-preemptive

in preemptive scheduling we preempt the currently executing process, in non preemptive scheduling we allow the current process to finish its CPU burst time 

in non preemptive scheduling the process at running state can not be forced to leave the CPU until it completes On a preemptive kernel, a process running in kernel mode can be replaced by another process while

in preemptive scheduling the process is forcibly sent to waiting state when a process with higher priority comes to CPU, 

When scheduling takes place only
under
:-

  • When a process switches from the running state to the waiting state (for example,
    an I/O request is being completed)
  • When a process switches from the running state to the ready state (for example
    when an interrupt occurs)
  • When a process switches from the waiting state to the ready state (for example,
    completion of I/O)
  • When a process terminates

 

REF :: handouts Page No. 80

 

Qno.22 Virtual machine V scheduling algorithm different steps

Answer:-

UNIX System V scheduling algorithm is essentially a multilevel feedback priority queues algorithm with round robin within each queue, the quantum being equal to1 second. The priorities are divided into two groups/bands:

  Kernel Group

  User Group

Priorities in the Kernel Group are assigned in a manner to minimize bottlenecks, i.e, processes waiting in a lower-level routine get higher priorities than those waiting at relatively higher-level routines. We discuss this issue in detail in the lecture with an example. In decreasing order of priority, the kernel bands are:

  Swapper

  Block I/O device control processes
  File manipulation

  Character I/O device control processes   User processes

REF :: handouts Page No. 91

 

Qno.23 If a process exits and there are still threads of that process running, will they continue to run?
Answer:-
i
f the thread in the process is running and receives a signal(say Ctrl-C) and the default action of the signal is to terminate a process, does the running thread terminates or the parent process will also terminate. That happens to the threads if the running process terminates because of some signal

REF :: http://stackoverflow.com/questions/3754018/threads-some-questions


Qno.24 What are the important characteristics of TestAndSet? What will be its advantage.
The important characteristic is that this instruction is executed atomically. Thus if two TestAndSet instructions are executed simultaneously, they will be executed sequentially in some arbitrary order.

Advantages :-

  • Simple to implement and understand
  • One memory location for arbitrarily many CPUs

REF :: handouts Page No. 106

 

Qno.25 Considering the Resource sharing feature of thread, what do you think is 'resource sharing' an advantage of a thread or disadvantage of a thread. Explain yours answer briefly.

Answer:-
The Advantages and Disadvantages of Threads

Four main advantages of threads are:

1.  Responsiveness:  Multithreading an interactive application may allow a program
                to continue running even if part of it is blocked or is performing a lengthy
                operation, thereby increasing responsiveness to the user.

2.  Resource sharing: By default, threads share the memory and the resources of the
                process to which they belong. Code sharing allows an application to have several
                different threads of activity all within the same address space.

3.  Economy: Allocating memory and resources for process creation is costly.
                Alternatively, because threads share resources of the process to which they
                belong, it is more economical to create and context switch threads.

4.  Utilization of multiprocessor architectures: The benefits of multithreading of

multithreading can be greatly increased in a multiprocessor environment, where each thread may be running in parallel on a different processor. A single threaded process can only run on one CPU no matter how many are available.

Multithreading on multi-CPU machines increases concurrency.

Some of the main disadvantages of threads are:

1.  Resource sharing: Whereas resource sharing is one of the major advantages of
                threads, it is also a disadvantage because proper synchronization is needed
                between threads for accessing the shared resources (e.g., data and files).

2.  Difficult programming model: It is difficult to write, debug, and maintain multi-
                threaded programs for an average user. This is particularly true when it comes to
                writing code for synchronized access to shared resources.

REF :: handouts Page No. 70

 


--
Zindagi mein 2 Logo ka buhat khayal rahkoooo
Ist woh jiss ney tumhari jeet ke Liye buhat kuch hara hoo
(Father)
2nd woh jiss ko tum ney har dukh me pukaara hoo (Mother)
Regards,
Umair Saulat Mc100403250

--
--
For study materials, past papers and assignments,
Join VU School at www.vuscool.com
 
Facebook Group link
http://www.facebook.com/groups/vuCoooL
 
CoooL Virtual University Students Google Group.
To post to this group, send email to coool_vu_students@googlegroups.com
 
home page
http://groups.google.com/group/coool_vu_students?hl=en