2022-08-12
Today I added pipes to my shell! This is the functionality my shell supports:
/home/nasreen/projects/shell>> cd ..
/home/nasreen/projects>> cd shell
/home/nasreen/projects/shell>> echo hi && echo bye
hi
bye
/home/nasreen/projects/shell>> ls
shell.py
/home/nasreen/projects/shell>> ls | wc -l
1
The code is here.
I'm going to call this project done for now. My goals when I started were to write a minimal functioning shell and learn a bit about how a shell interacts with the operating system, and I've done both of those! I also had fun and learnt some cool linux things I wasn't expecting. There are a bunch more things I'd like to add, but there are other things I'd like to do next week - maybe I'll come back to it (or maybe not)!
Some things I learnt while doing this:
a shell is basically just system calls + input processing (a full shell would also support a scripting language, but in a way that's just more advanced processing)
cd is a system call - it updates the working directory in the process
the shell is running in (it's actually a piece of state associated with the process)
all other system calls happen in a child process. Parent and child processes
can be distinguished by what fork() returns: 0 in the child process, and the child's
PID in the parent process
file descriptors are how processes keep track of open files (as well as input/output streams). The kernal keeps track of full file information for all open files system wide - the process has to make a call to the kernal to get that
the Python os module is pretty cool. When I started this, I wasn't sure if I'd be able to get very far in Python, but it turns out that the os module supports all the system calls I would have made if I did this in C
proc is a virutal file system with lots of information about what's happening
in the linux kernal
Today I also participated in a discussion about how to facilitate more pair programming at RC which was really interesting. And I attended presentations - really cool to see some of the projects people are working on.
I've had a great first week of my batch - I got to meet lots of kind people and have lots of interesting conversations. I'm really looking forward to the next 11 weeks.
Next week my goal is to pair program more. I'll probably try and do smaller stand alone projects with other people, and I'll focus on planning and doing pairing sessions rather than having an ongoing project of my own.