/C-Shell

A Linux shell written in C to implement inbuilt shell commands and some user-defined commands. Background and Foreground processes can be executed. Piping, Redirection and Signal Handling are also implemented.

Primary LanguageC

C-Shell

A shell in C language which supports most functionalities of a Unix shell like I/O redirection, piping, job control etc.

Division of Code:

  • headers.h contains function declaration for all functions.
  • The other files have the code for implementing the tasks suggested by the name of the files.
  • The code starts executing from main.c from where all other functionalities are performed.

Assumptions:

  • The history will be displayed for maximum 20 latest commands.
  • At max 100 commands will be given in one line.
  • Each command is less than 100 characters.
  • All paths involved are less than 1000 characters.

Features:

  • Builtin commands - {cd,pwd,echo}.
  • ls command - implemented various flags including -a - l.
  • System commands with and without arguments.
  • Foreground: process waits until the commands get executed.
  • Background: process doesn't wait for system commands get executed.
  • Upon completion of background, a completion message is prompted.
  • Repeat command to repeat a command multiple times.
  • pinfo command to display process information.
  • jobs: it displays information of the currently running background processes
  • sig: it kills a background process
  • fg: it brings a background process to foreground and runs it
  • bg: it stops a running background process.

How to run the shell:

  • The makefile will compile the code.
  • Enter make command to compile the code.
  • The shell can be executed by running the ./a.out executable.
  • ./a.out to run the program.
  • Enter quit to exit the shell.

Redirection and piping:

  • Redirection and piping functionality has been added in the input.c file
  • In this file, the redirections of inputs and outputs have been handled.
  • Piping of commands is also implemented in the same file.

Signal Handling:

  • ctrl + c : terminates any running foreground process
  • ctrl + z : sends a foreground process to background and changes its state from running to stopped.
  • ctrl + d : terminates the shell.