Code Monkey home page Code Monkey logo

syck-shell's Introduction

SHELL in C

A shell with basic functionalities with io redirections and piping support.
It can run system commands ,both in foreground and in background.
For compiling the shell run

foo@bar>./make

for running it

foo@bar>./shell

Has some builtin commands:

  • echo
  • cd
  • pwd
  • pinfo
  • ls , with -a , -l flags supported
  • exit, quit
  • setenv
  • unsetenv
  • jobs
  • fg
  • bg
  • kjob
  • overkill

Limitations:

  • Doesen't support quoting arguments or whitespace escape.

What i,ve learnt from this assignment:

Basic functionalities of shell and how processes execute
Expisure to new system calls and library functions
Modular coding
Understanding how io, redirections and piping works

Debugging pain gains:
  • End the input with NULL if using malloc to avoid random chars in buffer, or simply use calloc.
  • Not to run certain builtin commands as child processes, example: cd when run as child , it changes directory and exits, but parent ends up remaining in the same directory.
  • Not to allocate strings pointers directly for a variable, we can end up messing up the orginal string, so make a duplicate of it by strdup() or strcpy()
  • While implementing ctrl-z when the process stopped, i tried send the child process to new group by setpgid(pid,0), but it gave permission error;
    Fix: Irrespective of whether bg of fg process, i sent the child to new group, if it is an fg ,in the parent interface it with terminal's io by tcsetpgrp(0, pid);

Structure:

  • cykshell.h : the header file having main libraries, global constants , variables and functions.

  • shell.c : main() function;

  • interface.c : functions related to interface

    init(): initialises the terminal,
    prompt(): displays prompt in the terminal ,
    cwd_func(): stores current working directory shortened and previous directory
    inputt(): takes in input splits it into commands
    cmd_in(): takes in command splits into arguments
    stringseperator(): takes a string and return array of strings splitted with delimter

  • cmd_exec.c : Command execution takes place

    cmd_exec(): takes in arguments of a command and executes it.
    buitlin_exec(): executes builtin commands.
    bg_check(): check if it is a bg process.
    bg_end(): display if background process ends.
    delbg() to get process name of pid and delete if neccesary.

  • colours.c : just storing few colour functions

  • builtin.c : few small builtin functions pwd_b() cd_b() echo_b() exit_b()

  • ls_exec.c : ls command by ls_exec() function

  • pinfo_exec : pinfo command by pinfo_exec() function

  • ioredir.c : ioredir() function for redirections.

  • pipe.c : for piping the commands

  • killakill.c : kjob and overkill implementation.

  • jobsrelated.c : jobs , fg and bg implementation

  • signalhandler.c : signal handling for ctrl-c and ctrl-z

Assignment 3 bonus: cd -

(P.S: The code was compiled in arch distro, it wasnt compiling unless -fcommon was used, if it doesent compile, pls use appropriate flags in makefile and try again.
Thank you)

syck-shell's People

Contributors

95ych avatar

Watchers

James Cloos avatar  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.