Skip to content

Latest commit

 

History

History
170 lines (126 loc) · 6.15 KB

blog.md

File metadata and controls

170 lines (126 loc) · 6.15 KB

$ psh: a fancy POSIX-like shell

Authors : KK, Adi, Alayna, Sumithra, Siddhartha

Contents :

Introduction

  • What made us choose this project ?
  • As computer science students, we work with shells on a daily basis. Hence, building a shell from scratch was a great opportunity for us to explore its inside workings while tweaking it to match our custom needs.

It is a part of Tilde 3.0 HSP PESU-ECC's summer mentoring program: where 5 students developed this project under the guidance of 4 mentors. Under this program, we have developed psh, a custom POSIX-like compliant shell. It is implemented in C and aims to achieve all features of POSIX compliance while incorporating other features that set it apart

Contributors:

Mentors:

From the ground up

  • Here is some background info you might require before diving into our project...

What is a Shell ?

  • A shell is an cli interface that acts as an intermediary between a user and an operating system's kernel

  • Instead of using a graphical interface with buttons and menus, you type commands into the shell to control your system, like managing files or running programs.

  • Examples : bash, zsh, fish

What is POSIX standards

POSIX is a family of standards, specified by the IEEE, to clarify and make uniform the application programming interfaces provided by Unix operating systems. POSIX compliancy implies your shell/shell utility can be ported anywhere across wide range of UNIX (derivatives)

Working of a shell under the hood

So here's what exactly happens when you type a command in a shell, lets you want to execute a command call it 'X' so when you type it in the shell and hit enter. Your shell first checks whether the 'X' is an shell-builtin or a shell executable..

Whats a shell builtin ?

  • It is a command or a function, called from a shell, that is executed directly in the shell itself, instead of an external executable program which the shell would load and execute. Shell builtins work significantly faster than external programs, because there is no program loading overhead

Whats a shell executable ?

  • These are commands stored in /usr/bin/ or /usr/local/bin

shell

Genesis

How we started with psh ?

  • Firstly we implemented a REPL algorithm which is basically an infinite while loop, awaiting user response for further commands.

All About psh

File Strucure :

├── bin
│   ├── builtin.o
│   ├── execute.o
│   ├── helpers.o
│   ├── main.o
│   └── psh
├── Makefile
├── README.md
├── script.sh
└── src
    ├── builtin.c
    ├── builtin.h
    ├── colors.h
    ├── execute.c
    ├── helpers.c
    ├── main.c
    └── psh.h

WorkFlow of psh


Commands

  • We have 2 set of commands

    1. shell builtin : cd, exit, echo, type, pwd, fc, export, read, alias, unalias
    2. external : ls, lsblk, ssh, file, script

Main Features

  • Script mode
  • Syntax highlighting
  • Signal handling
  • Arrow keys
  • Auto complete
  • Globbing

How you can run psh locally ?

git clone https://github.com/homebrew-ec-foss/psh 
cd psh
make run

Benchmarks

psh is memory efficeint with almost 0 memory leaks

YESS IT IS VERY MEMORY SAFE

here is time to execute a script using bash and psh

bash : psh :

As you can see psh is almost as fast as bash

Experiences

It was an overall fUn experience, learning fundamental concepts of os and understanding how shell works 🤯. We also had a tough time debugging C code as we kept running into segmentation faults, as well as learnt how to use gdb to get rid of segmentation faults. We learnt how to handle memory leaks and dynamic memory allocation in a much more efficient manner for a large codebase. Resolving merge conflicts was a new and slightly tedious experience.

Our mentors gave us some wonderful suggestions and feedback as to how to go about making this project. Their support has been instrumental. Tejas screaming was music to our ears 🥺

Fun stuff

here is Nathan merging pr through psh shell 😊



References