Division without / or *

December 28, 2010

Q: Write a function to perform integer division without using either the / or * operators. Find a fast way to do it.


void int_div(int dividend, int divisor)

remainder = 0;
quotient = 0;

while(remainder > divisor)
remainder = dividend - divisor;
quotient += 1;

Read the rest of this entry »


Supernatural : Tv Show

May 3, 2010
Supernatural Tv Show

Supernatural Tv Show

Off late I have been watching a Tv Show called Supernatural. At first I didn’t think much of it, almost pegged it as one of those mindless GhostBuster types. But soon realized that there is more to it. Well, the whole point of existence of Ghosts, spirits, Zombies, Daemons etc… is debatable. I feel (even before watching this show) that there is more than that meets the eye. What we see or feel need not be ALL of what’s present around us. A spooky idea but nevertheless worth discussing…

Well there could be scientific arguments in this. Normally humans perceive (or see) length, breadth, height & perceive time. That makes us see & perceive 4 dimensions. But according to String Theory, we live in a 11-Dimensional Space. So what could the other dimensions account for?

Ruby - The Deamon

Ruby - The Deamon

Coming back, most Tv Shows that I see to be afraid of innovating. Or they end up changing so much that the main focus of the show is lost. This is one show where I noticed constant changes while still keeping the interest of the viewers, a tried & tested cast is not dragged on for more shows than was necessary.

Debugging NGinx

April 22, 2010

NGinx is a lightweight, high performance web server & reverse proxy. It’s fast becoming popular & is touted to take on Apache as a preferred browser. It uses far lesser Operational memory than Apache, plus it consumes lot lesser CPU Cycles. All this is mostly due to its architecture. Credit has to be given to Igor Sysoev who’s single-handedly done this !


NGinx Webserver

Off late, I have been tinkering NGinx code. But as any programmer would vouch, debugging is a very much integral part of programming. There are no direct manuals available for the same. For any beginner this new web server along with new environment can be daunting. Here’s a low-down on how to use gdb to debug NGinx.

First of, make sure you take care of these –

  1. Install all the dependencies that NGinx requires.
  2. Compile NGinx from source. The standard NGinx binaries (got from apt-get or yum or other package managers) haven’t been built with debugging on.
  3. Make sure you check out all the available options that are available at compile time. Check here for that.
  4. If all is well, NGinx would have compiled fine. It would have installed under ‘/usr/local/nginx’.
  5. Go there and open ‘conf/nginx.conf’. You might see “worker_processes <some_number>”, edit it to “worker_processes 1”. Save & close the config.
  6. Now start the server by typing ‘/usr/local/nginx/sbin/nginx’. nginx starts with one main process + 1 child process (as we specified in config).

Now the web server is started & is running. It should serve requests. Test it by typing any local url in your browser. The next points, should be typed as is in command-line.

  1. gdb
  2. file /usr/local/nginx/sbin/nginx
  3. After this if you want to put breakpoint at any place then put – b ngx_http_<your_filename>_module.c:19
  4. Next open another terminal session & type “ps -ef | grep nginx”, this tells you that there are 2 nginx processes running. One Master, One Child. Get the pid of the child process.
  5. Come back to your gdb prompt & type – attache <pid_of_child_process>
  6. Type continue, to resume normal execution.
  7. Goto the browser & navigate to the url location where your module would get activated.
  8. You should break at the file where breakpoint you mentioned.

Enjoy debugging 🙂

PS: One thing I couldn’t figure out was that NGinx does not seem to server requests from master process. Why is that? Is it a design decision?

Coming up…

March 20, 2008

New posts coming up.