Pipes, Forks, & Dups: Understanding Command Execution and Input/Output Data Flow

I'm currently enrolled in a systems programming class at Stanford (CS110: Principles of Computer Systems). It is the second systems class I've taken (the first was CS107 which teaches C and focuses on understanding pointers and memory management). This class focuses mainly on the inner workings of the operating system, using C and C++ to teach us concepts like process management, program execution, and handling data. While I enjoyed and quickly grasped the concepts taught in CS107, I've had a harder time understanding the material in CS110. The class itself is extremely interesting and well-taught, but my main pain point has been understanding the way processes share data and how input and output work across commands entered in the terminal. In the last few days, however, I finally found clarity when I started creating diagrams to model process behavior and the path that data takes as it travels from one command to another. I'd like to share what I've learned with you. In this post, we'll go over how Unix commands pass data to each other via pipes and input/output redirection and I'll illustrate what actually happens to the flow of data when a command is executed.

Fun with Fractals

There is an interesting intersection between math, computer science, and art that has fascinated me for years, but I didn’t realize how strong the math and computer science components are until my studies at Stanford. The topic represents some of the most beautiful and mathematically sound forms of digital art and nature itself: fractals.

Probability: Finding The Expectation and Variance of Runs

Last week, I completed a summer course at Stanford: CS109, Probability for Computer Scientists. This 8-week long class was intense and challenging but one of the most rewarding classes I've taken at Stanford so far. A few weeks ago, I had an idea for a homework problem but I couldn't quite figure out how to implement the idea. The problem is the following: Below are two sequences of 300 “coin flips” (H for heads, T for tails). One of these is a true sequence of 300 independent flips of a fair coin. The other was generated by a person typing out H’s and T’s and trying to seem random. Which sequence is the true sequence of coin flips? Make an argument that is justified with probabilities calculated on the sequences. Both sequences have 148 heads, two less than the expected number for a 0.5 probability of heads.