Tuesday, December 18, 2012

fork() explosion!

Quick summary: I discovered that an infinite loop calling only fork() is a terrible idea. I hope I don't get an angry email from a system administrator any time soon!

I've been home for two days, and my goal has been to finish the Unix Shell assignment for my programming systems class.

Just a few minutes ago, I learned how important it is to be careful when working with system calls like fork(). I wrote a program (on the Princeton server) which consisted of an infinite loop that called fork() once for each iteration. It seemed like a pretty harmless program. After, all I could always use Ctrl-C to terminate the infinite loop, right?

Wrong. And it should have been clear from the start that this was a terrible idea. Each child process created by the fork() is another infinite loop that spawns infinitely many more child processes! And this continues recursively! So my original process and all its children were soon taking over the entire system! Ctrl-C didn't work, so I closed the terminal window and logged back in.

Issuing the top command, I could see hundreds of copies of my program running, and taking up over 90% of the system CPU. After unsuccessful attempts to kill all these processes, a system administrator must have realized that something was wrong and terminated everything for me. Now, things are back to normal (or they seem to be at least).

Oops. I hope I don't get an angry email from a system administrator any time soon!

Saturday, December 8, 2012

LaTeX test

$a^2 + b^2 = c^2$

Knowing math jokes helps for the Putnam!

I spent 6 hours on Saturday 12/1 on the Putnam 2012 Exam. In both parts, I solved the first two problems in an hour, and spend the remaining two hours making no progress. But my favorite part of the exam was how I solved B1.
Let $S$ be a class of functions from $[0,\infty)$ to $[0,\infty)$ that satisfies:

(i) The functions $f_1(x)=e^x-1$ and $f_2(x)=\ln(x+1)$ are in $S;$

(ii) If $f(x)$ and $g(x)$ are in $S,$ the functions $f(x)+g(x)$ and $f(g(x))$ are in $S;$

(iii) If $f(x)$ and $g(x)$ are in $S$ and $f(x)\ge g(x)$ for all $x\ge 0,$ then the function $f(x)-g(x)$ is in $S.$

Prove that if $f(x)$ and $g(x)$ are in $S,$ then the function $f(x)g(x)$ is also in $S.$
This probably at first looked super complicated, and I wasn't sure how to start. But then I thought of the following math joke:
Noah's Ark lands after The Flood and Noah releases all the animals, saying, "Go forth and multiply." Several months pass and Noah decides to check up on the animals. All are doing fine except a pair of snakes. "What's the problem?" asks Noah. "Cut down some trees and let us live there," say the snakes. Noah follows their advice. Several more weeks pass and Noah checks up on the snakes again. He sees lots of little snakes; everybody is happy. Noah says, "So tell me how the trees helped." "Certainly," reply the snakes. "We're adders, and we need logs to multiply."

(Source: http://www.math.utah.edu/~cherk/mathjokes.html)
And soon after I remembered this joke, I wrote down a solution!

Sieves!

Our most recent problem set in Analytic Number Theory focused on sieves, so I have been thinking nothing except them. And this is true even though I turned in the problem set already! Two incidents this week:

  • While I was eating breakfast at 2D, someone asked for a sieve. My immediate first thought was "Selberg sieve or Brun sieve?" but I realized soon afterwards that she was referring to a kitchen utensil.
  • I overheard a grad student asking Professor Sarnak in the common room about a problem, and at one point, Sarnak asked "are you familiar with sieves?" I screamed out "I know how to do it!" across the room, and they turned around and stared at me. Sarnak then told the student "that young man can't solve this problem, but he can give you good upper bounds." And they went back to their discussion.

Saturday, December 1, 2012