Summary
- What Is It? – Custom Shell program implemented from scratch
- Technologies Used – C++
-
My Accomplishments
- Gained expertise on the use of syscalls
- Understood process management and filesystem navigation
- Learned C++ during project
What It Does
This program implements many of the common Unix shell commands such as history, ps, pwd, cd, exit, kill, and others. It can be used as a fully functioning shell, allowing the user to navigate the filesystem, run programs, show active processes, and kill those processes.
How I Did It
The project primarily relies on the use of syscalls (system calls). Each command simply takes in inputs, formats the syscall with arguments, and then calls the syscall. The hardest part was learning how each of the different syscalls work, and when to use them. Aside from that, I also implemented a command history system and a process tracking system.
The command history system was created by keeping a buffer of commands, and writing that to a file upon program termination. On startup, the file is read back in. This allows the user to show previous commands and also replay any command. This was easy to integrate into the rest of the system.
The process tracking system was more difficult. I had to keep a vector of all processes spawned from the shell, and clear out a process anytime it sends an signal back to the shell that it has been killed. I then created the ps command by running through the current list of processes and pinging each one. If was still active, I displayed it.
What I Learned
One of the biggest things I learned from this project was C++. I had never used the language before. This was a school assignment and we were given the option to use C, Java, or C++. Since I was already familiar with the first two, I decided to challenge myself and try to complete the project in C++. I think having the other languages under my belt allowed me to pick this one up quickly, and I was able to complete the project plus the bonus.
I also gained a much better understanding of how to interact with the operating system through syscalls. There were many simple syscalls used in my program such as the ones for reading files or directories. The most confusing part of the program for me was understanding how the fork syscall works. I don’t think it is very intuitive, but now that I understand it, I know it is very powerful.
Learning these different syscalls, especially fork, allowed me to create a program that works with the operating system instead of just running on top of it. It also gives me a better idea of how other programs work under the cover.
Link to Code
Because this is a school project, I had to make the GitHub repo private. This link gives read access to the repo without making it public. Unix Shell Terminal Code