ravinet/mahimahi — pull request #12 by keithw (2013-09-01 16:30:28+00:00)
Title: Fork example

Ravi/Anirudh,

Today's clone example looks great. I didn't realize `clone()` required you to manually allocate memory for the child's stack -- that's pretty nasty. On reflection, I think `fork()` followed by `unshare()` is probably easier to think about, even if `clone()` is more powerful in some sense. We don't need all that power. :smile:

Anirudh is right that the parent should `wait()` for the child process -- because otherwise the terminal input won't go to the child if the parent exits right away. Another gotcha that hadn't occurred to me.

Here are some small fixes to the program you guys wrote (in general we want to avoid `malloc()` in C++ code, and we need to null-terminate the `argv` array). Then I rewrote it to use `fork()` and `unshare()` instead of `clone()`. Tell me if this looks clean enough for you.

Cheers from the shores of Lake Sebago,
Keith