Recent Posts

1161

Masters is not very different from Bachelors but in India most students do Masters from IITs and there is a big gap to be filled from lower level college environment. Though GATE preparation is mostly enough a few extra stuffs might come handy during IIT life. 

  1. Get used to unix commands: I first started using linux only in second year of Masters and though I have used it ever since I still think 2 years early start would have helped me a lot. Somethings to try- 
    Install linux (ubuntu or mint or any other) either as dual boot (preferred) or as VM. If you have a credit card you can even get Amazon AWS free for 1 year (it is good). 
    Try running a process in background.
    Try ssh to/from another machine and run a process in background (cronjob, nohup etc. might be needed here). 
  2. B.Tech. level C/C++ skills is enough. But depending on how you did B.Tech. you might need to hone it. Try implementing graph traversals, AVL tree etc. in C and even try using STL in C++ for doing so. 
  3. Java might not be required for B.Tech, but if needed no one is going to send you for a Java coaching. It is actually a subset of C++ (Java is made to make C++ easier), and anyone coding in C++ must be able to use Java. Try some String algorithms in Java. Another use of Java is for programming interviews- it is much simpler (and faster) to use Java to write a code than with C/C++ and even in Google programming interview Java is preferred.
  4. $\LaTeX$ is a publishing tool which all CS students should have used. In IITs, it might be used for assignments, report submissions etc. So, try making your resume in Latex, convert your B.Tech. report to latex one etc. If you have used Mathjax on website (as in gateoverflow), it would be pretty simple. 
  5. Plotting is a needed research tool. There are many shortcoming with using Excel and trying to use gnuplot might come handy during Masters. 
  6. Data analysis is another demanding task- and trying some basic R commands- like finding mean, SD etc. is recommended. Trying Python might also be handy. 
  7. awk - is fun to use. Use it especially if you want to process a text file line by line. 
  8. Whatever you do an editor is important. Knowing commands of a smart editor like vim, emacs etc. can make your work more fun and easier. Using IDEs like Geany, Eclipse etc. are also highly useful as they will reduce many jobs in future.
  9. Being familiar with area specific tools- like installing LLVM if you are interested in Compilers, R language if you are interested in data analytic, making shared libraries if interested on system side, mastering regular expressions if working on text processing and similarly for other areas.
  10. If you are interested in system side, be familiar with gdb
  11. Any project would require versioning and being familiar with git is an added advantage. 
  12. For placements, aptitude- some companies ask CAT level questions - is required. Also, for big software companies, dynamic programming is important. Do practice some questions like sudoku solving using backtracking also. These questions can also help. 
  13. In most places, you will have time for deciding the area of work. Still, if you can find a suitable prof to work under early, it is a good thing. Otherwise also, you can do this in first year. 
1162
CMSC 421 Operating Systems Lecture Notes
(c) 1994 Howard E. Motteler


Interprocess Communication
===========================

(Section 2.2 in Tannenbaum)

Interprocess communication is fundamental to

  - client-server applications (e.g. X windows)
  - modern threaded operating system design
  - many systems utilities in *any* OS (e.g. print spoolers)
  - parallel processing

There are two general models of interprocess communication

  - Shared memory with synchronization operations
  - Message passing


Shared Memory with Synchronization Operations
==============================================

Shared memory must be managed carefully.

Example of 2 processes writing to a shared buffer:

Suppose that both the pointer p and the buffer it points to are
shared by processes P0 and P1

[ show pix of buffer and pointers ]

Suppose that

      -  P0 contains  *p++  =  a ;
      -  P1 contains  *p++  =  b ;

If both P0 and P1 execute these statements once, we expect

      -  p is incremented twice
      -  both  a  and  b  are saved (in some order)

The statement *p++ = a typically is implemented by at least 
two machine instructions

      -  *p = a ;
      -  p++ ;

Consider the following possible sequence of events, where two
processes both copy data to a buffer

P0:                 P1:
     :                                       |
  *p = a ;                                   |
  (context switch)                         time
                         :                   |
                      *p = b ;               |
                       p++   ;               V
                         :
                      (context switch)
   p++   ;
     :

The value `a' has been overwritten by `b'

This is sometimes called a "race condition," because the
final result depends on instruction timing

The *last* variable assigned "wins", i.e., gets saved


Mutual Exclusion in Critical Sections
--------------------------------------

A ``critical section'' is a part of a program that accesses
shared data

A program can have several critical sections for different
data

The ``mutual exclusion problem'' is to find a way to guarantee
that only one process at a time can access the shared data


A solution to the mutual exclusion problem should satisfy

  1. `mutual exclusion:' only one process in a critical 
      section at a time

  2. `progress:' a process outside a critical section can't
      hold up others that want into that critical section
 
  3. `bounded waiting:' a process waiting to enter a
      critical section eventually gets in

  4. `timing:' no assumptions are made about speed, timing, 
      or number of CPUs
   


Disabling Interrupts
--------------------

The simplest way to get mutual exclusion is to disable
interrupts when a processes enters a critical section

Without clock interrupts, there's no context switch

Problem: user would need special `enter' and `exit' critical
section commands, and these commands could be used to hog the
CPU

Disabling interrupts is sometimes useful for the kernel itself



Two-process software solutions to the Mutual Exclusion Problem
---------------------------------------------------------------

We will try and develop some code to ``guard'' a critical
section, so it can be shared by two processes

All these methods use ``busy waiting'' which is sometimes
unavoidable.


Simple Locks
------------

Suppose we have a shared `lock' variable, initially 0 and set to
1 whenever a process is in its CS

P0, P1:
   while ( lock != 0 ) ;     // wait until lock is 0
   lock = 1                  // set lock
   CS() ;                    // enter the critical section
   lock = 0 ;                // reset lock

Problem:

    P0:                     P1:
    finds lock = 0,
    (context switch)
                            finds lock = 0,
                            sets lock = 1,
                            enters CS
                            (context switch)
    sets lock = 1,
    enters CS

Mutual exclusion fails just as in our initial example
with the shared buffer


Alternation
-----------

Suppose we allow the processes to take `turns'

P0:
while (alive) {
   while ( turn != 0 ) ;     // wait until turn = 0
   CS() ;                    // enter the critical section
   turn = 1 ;                // other process's turn

P1:
while (alive) {
   while ( turn != 1 ) ;     // wait until turn = 1
   CS() ;                    // enter the critical section
   turn = 0 ;                // other process's turn


Mutual exclusion is satisfied, but `progress' fails

Suppose P0 enters and leaves its critical section

Then P0 cannot re-enter the critical section until P1 enters and
leaves its critical section


Flags for `in the CS'
---------------------

Idea: use two flags, both FALSE initially; flag0 is true 
when P0 is in CS, flag 1 is true when P1 is in the CS

P0:
while (alive) {
   while ( flag1 ) ;   // wait until flag1 = false
   flag0 = TRUE ;
   CS() ;
   flag0 = FALSE ;
   }

P1:
while (alive) {
   while ( flag0 ) ;   // wait until flag0 = false
   flag1 = TRUE ;
   CS() ;
   flag1 = FALSE ;
   }

Mutual exclusion fails:

    P0 does `while' test, finds flag1 = FALSE
    P1 does `while' test, finds flag0 = FALSE
    P0 sets flag0 = TRUE and enters CS
    P1 sets flag1 = TRUE and enters CS


Flags for `want to enter' (similar to previous example)
--------------------------------------------------------

P0:
while (alive) {
   flag0 = TRUE ;
   while ( flag1 ) ;   // wait until flag1 = false
   CS() ;
   flag0 = FALSE ;
   }

P1:
while (alive) {
   flag1 = TRUE ;
   while ( flag0 ) ;   // wait until flag0 = false
   CS() ;
   flag1 = FALSE ;
   }

In this case `progress' fails

P0 sets flag0 = true
P1 sets flag1 = true

and both are stuck!


Peterson's Solution
-------------------

Use both a turn and flag variables; both flags are initially
FALSE.   (Flags are for "want to enter")

P0:
while (alive) {
   flag0 = TRUE ;
   turn = 1 ;
   while ( flag1 && turn == 1 ) ;   // wait until flag1 = FALSE 
   CS() ;                           //            or turn = 0
   flag0 = FALSE ;
   }

P1:
while (alive) {
   flag1 = TRUE ;
   turn = 0 ;
   while ( flag0 && turn == 0 ) ;   // wait until flag0 = FALSE
   CS() ;                           //            or turn = 1
   flag1 = FALSE ;
   }


Partial analysis

  -Suppose P0 wants CS, and P1 is not in and does not want CS:
   Then P0 enters CS, as flag1 is FALSE (part of progress)

  -Suppose P0 wants CS, and P1 is in CS.
   Then P0 waits for flag1 to go FALSE (mutual exclusion)

  -Suppose both P0 and P1 want CS
   Then the *first* one to set turn is the one to get in
   (mutual exclusion & progress)


   P0  flag0 = TRUE;
   P1  flag1 = TRUE;
   P0  turn  = 1;
   P1  turn  = 0;                   P1 is second to set turn
   P0  while (flag1 && turn == 1)   false, turn is 0, so enter CS
   P1  while (flag0 && turn == 0)   true, loop until P0 leaves CS,
                                    enter CS when flag0 goes FALSE
Must check bounded waiting:

  - Suppose both P0 and P1 want to enter the CS
  - P0 sets turn=1, P1 sets turn=0, P0 enters CS
  - P1 is waiting in while loop for either flag0 to be FALSE,
    or for turn to be 1

  - Suppose P0 exits CS
  - P0 sets flag0 = FALSE;
  - Suppose P1 is unlucky
  - P0 sets flag0 = TRUE before next P1 test
  - P0 sets turn = 1
  - P1 enters CS on turn = 1



Hardware for Critical Sections
-------------------------------


The `Test & Set Lock' Instruction
---------------------------------

Suppose we have a machine instruction TSL(v)
that `atomically' (i.e., uninterruptibly) 
      - sets v to TRUE
      - returns the old value of v


Then it is very easy to protect a critical section with a
`lock' variable:

entry:   while TSL(lock);     // wait until lock is FALSE
         CS();
exit:    lock = FALSE;

How it works:

Suppose we hit `entry' and lock is
1164

Reference: Hamacher

1167
Hi guys, just wantedbto share something with you. Most of us find maths as a 'just on paper' thing and so, somewhat boring (no offense). That's almost true, provided you have never approached it in a practical way. But, here's something I found today while surfing. It turns out to be a damn good website for boosting up the interest in Mathematics. Main focus of the organization is on discrete but still they will roam you through the interesting history and future applications. Thought it will be a good suggestion for gate aspirants.

Here's the site: www.mathigon.org

For graph theory, chekout http://world.mathigon.org/Graph_Theory

Hope, it cheers you a bit.

(P.S. - I am not anyone's promotion agent. I just found the content useful, that's why took my time out to write this :) )
1169

Important Questions

http://gateoverflow.in/questions/algorithms?sort=featured

Sometimes we need to walk through a given algorithm to get the answer. These questions must not be missed as there is very little chance of a mistake. 

1173
1174

Important Ones

http://gateoverflow.in/questions/programming-in-c/ds?sort=featured

More Questions

Topic Source Link Solution
Linked Lists IITKgp  Assignment- IA Linked Lists   Solutions
Stack, Queue IITKgp Assignment- IB Stack Queue Solutions
Binary Trees IITKgp Assignment- IC Binary Trees Solutions
Arrays, Sets and Hash-tables IITKgp Arrays, Tables and Set NA
B+ Trees IITKgp B+tree NA
Graphs IITKgp Graphs NA

 

 

1179
  1. Split the fd's such that rhs contains single attribute. 
  2. Find the redundant fd's and remove redundant ones. 
  3. Find the redundant attributes on lhs and remove them.like AB->C ,A can be deleted if closure of B contains A