Skip to content

Bhargavi-hash/Linux-Shell-Implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OSN: LINUX shell implementation in C

Running the Shell

  1. run make in the extracted directory
  2. run ./shell

Brief Overview

  1. This shell supports most linux shell functionalities including semicolon separated commands, piping, redirection, all basic linux commands etc.
  2. Foreground and Background processes can also be executed.

The commands that are supported are as follows :

  • pwd : prints the present working directory.

  • cd : changes the directory based on the flags given.

    • cd
      cd .
      cd ..
      cd ~
      cd -
      cd <directory>
  • ls : lists the contents of a particular directory based on the flags given.

    • ls
      ls -a
      ls -l
      ls -al
      ls -la
      ls -a -l
      ls <directory>
      ls <flags> <directories>
  • echo : prints a message on the terminal

    • echo <"Hello World">
  • pinfo : lists the details of a particular process (may be based on a process ID that is given).

    • pinfo
      pinfo <pid>
  • Foreground Processes: Processes that require the terminal to halt until their completion. Example:

    • vi
      emacs
  • Background Processes: Processes that run simultaneuosly without interrupting the terminal. Example:

    • emacs &
  • Input output redirection : Redirects input or output to appropriate files. Example:

    • cat file1.txt > file2.txt
      sort < sort.txt > sorted.txt
  • Piping commands : Pipes two or more commands together. Example:

    • cat test.txt | grep a
  • Piping with redirection : Example :

    • sort < sort.txt  | grep a | wc > lines.txt
  • setenv : setting new environment variables. Example :

    • setenv a 15
  • unsetenv : unsetting an environment variable

    • unsetenv a
  • jobs : prints all the background jobs

    • jobs
  • kjob : Sends a signal to a particular job number

    • kjob 1 9
  • fg : brings a running or a stopped background job with given job number to foreground.

    • fg 1
  • bg : changes a stopped background job to a running background job.

    • bg 1
  • overkill : kills all background process at once.

    • overkill
  • The terminal also supports

    • CTRL + Z

    • CTRL + C

    • CTRL + D

Running the Shell

In order to run the shell run the following command.

    make
    ./shell

Exiting From the shell

To exit from the shell, use the command

quit

Pseudo Home

The directory in which our ./shell is present

Code Files and Functions

  • myshell.c:

    • promptprint(): function to print th shell promt.

    • loop(): runs the main loop of the code for the continuous execution of the shell.

    • del_process(): function that accounts for the child processes that have terminated and thereby removes them from the process array.

    • done(): function that is to be executed as soon the parent process is interrupted by a signal of the termination of any of its child processes.

  • pwd.c:

    • pwd(): function that prints the present working directory.
  • ls.c:

    • The flags -a, -l, -la, -al can be used. Complete or absolute path of a directory can also be provided to list the contents of that directory.

    • Trigger_ls(): Extracts flags.

    • ls_command_1(): Checks for the properties of directories.

    • ls_command_2(): extracts names of diretories and files parsed.

    • Check_For_File() : Checks for the properties of files.

  • cd.c:

    • cd (): The directory will be changed the argument provided if it is valid.
  • echo.c:

    • echo(): Prints a string argument on the terminal. Handles cases with and without quotes.
  • pinfo.c():

    *pinfo(): Provides details about currently active/running processes. A particular process ID can also be provided as an argument to obtain its details.

  • foreground.c:

    • foreground(): Forks the existing process and runs a child process in the foreground. The parent process resumes once the child terminates and waits till then.
  • background.c:

    • back(): Forks the existing process and runs a child process in the background. The parent process continues to run alongside the child process. Once the child terminates, the exit satus of the child process prints on the screen.

    background processes for built in commands are not supported

  • history.c:

    • history_command(): stores all the implemented commands in the history.txt file so that we can access them in the next session.

About

Implementation of Linux Shell in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages