Giter Club home page Giter Club logo

basic-shell's Introduction

Basic shell

Basic shell with job control. It offers the most basic functionality of a linux shell, a program that allows the execution of processes. Processes can be interrupted, continued, and executed on the background.

๐Ÿ“Œ Summary explanation.

Compilation

Clone the repo and launch makefile.

$ make

Alternatively, compile as:

$ gcc -o shell -Wall src/main.c src/signals.c src/jobs.c src/wrappers.c

An executable shell will be generated.

Features

  • Runs executables in the current working directory or the specified path.
  • Runs one process in the foreground or several in the background.
  • The foreground job can be terminated by typing Ctrl+C and stopped by typing Ctrl+Z.
  • Built-in commands: fg, bg, jobs, and quit.
    • fg <id>: send the process specified by <id> to the foreground.
    • bg <id>: send the process specified by <id> to the background.
    • jobs: displays a list of currently active jobs.
    • quit: terminate the shell.
  • Processes can be identified by a process id (PID) or a job id (JID) preceded by %.
> bg %1      // Resume job with JID=1
> bg 14501   // Resume job with PID=14501
  • Exit shell by pressing Ctrl+D or typing quit.

Example shell session

For this demo, wait and write are dummy executables present on the current working directory that run in an infinite loop. The ^C and ^Z characters below are the result of typing Ctrl+C and Ctrl+Z.

$ ./shell
> ls
ls: Command not found.
> /bin/ls
jobs.c	 jobs.h   main.c   Makefile   README.md  signals.c   signals.h	wrappers.c   wrappers.h   write
jobs.c~  jobs.h~  main.c~  Makefile~  shell	 signals.c~  wait	wrappers.c~  wrappers.h~
> wait &
[1] 17715			wait &
> wait
^Z
Job [2] 17716 stopped by signal: Stopped
> fg %2
^C
Job [2] 17716 terminated by signal: Interrupt
> write
1...
1...
1...
1...
^C
Job [2] 17718 terminated by signal: Interrupt
> wait &
[2] 17719			wait &
> jobs
[1] 17715 Running		wait  &
[2] 17719 Running		wait  &
> quit

Sources

  • Core read-eval loop taken from CS:APP.
  • Helper wrapper functions taken from csapp.c.

License

MIT

basic-shell's People

Contributors

fabrizzio-gz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.