Skip to content

vjspranav/C_Shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terminal Written in C

A custom terminal for Linux supporting bash commands with support for almost all built in functions either through system call or custom written built in function. Takes care of input output redirection with

ls > test.txt
sort < in.txt > out.txt

Does pipe handling (with IO redirection too)

ls | cat | grep test > out.txt

Requirements

GCC Version >= 10.2.0
Will work for lower Versions also but there could be unexpected warnings and errors.

How To Use

Run The Following command in the dir where you cloned the repo

make
./terminal

or Copy Paste the following

git clone https://github.com/vjspranav/C_Shell -b v1
cd C_Shell
make
./terminal

Custom Functions

  1. echo
echo string

Ignoring extra whitespaces prints on shell

  1. ls
ls <dirname> <dir2name> <filename> [options]

ls or ls -a or ls -l or ls -al/la with dirname(s) and/or filename(s) and/or no arguments list it out. Tried to mimic actuall shell output/performace with multiple folders given or files given.

  1. cd
cd dirpath

dir path could be relative or absolute. '.' would be in same dir, '..' to previous dir, '~' for terminal execute dir. Relative wrt to '~' is also allowed.

  1. history
history <num>

last 10 commands in history would be printed if no num is provided else last num number of commands will be printed. (Stores only last 20 commands)

  1. pwd
pwd

Print current dir path

  1. pinfo
pinfo

will give

pid -- 231
Process Status -- {R/S/S+/Z}
memory -- 67854{​Virtual Memory​}
Executable Path -- ~/a.out

or

pinfo pid

will give

pid -- (pid)
Process Status -- {R/S/S+/Z}
memory --123456 {​Virtual Memory​}
Executable Path -- /usr/bin/gcc

Gives info of the process with process id pid, if no pid is given the info of shell is shown.

  1. setenv
setenv <name> <value>

Set value to to variable name, if variable exists it's value is not overwritten, if no value is provided string.

  1. unsetenv
unsetenv <name>

Clears value of variable name.

  1. jobs
jobs

will give

<vjspranav@archlinux:~>$ jobs
[1] Stopped nano with id=21076
[2] Stopped vim with id=21078 
[3] Running sleep with id=21081

Will print a list of background running processes with jobnumber and pid

  1. kjob
kjob <jobnumber> <signal>

Will send kill signal signal to process id with job number which we get from jobs

  1. fg
fg <job number>

Brings the running or stopped background job corresponding to ​jobnumber​ to the foreground, and changes its state to ​running​. The shellshould throw an error if no job with the given job number exists

  1. bg
bg <job number>

Changes the state of a stopped background job to running (in thebackground). The shell should throw an error if no background jobcorresponding to the given job number exists.

  1. overkill
overkill

Kills all created background processes.

Files Description

All headers files have Macros and function definations for global accesibility of the functions in the respective C files

  • makefile

Compiles all objects and starts the terminal

  • headers.h

Has all the header Files required across the complete Terminal code also has the inclusion for childHandler.

  • commands.h

Has all the header File inclusions required for custom functions.

  • main.c

Main Driver Code That displays prompt and accepts input in a loop, also ahs the signal handler for when a child exits.

  • prompt.c

Gets the username and host name and creates the prompt part of shell

  • input.c

Takes the input from a string, parses it at semicolons and in a loop each command is space separated and sent to command handler as a 2d array.

  • commadHandler.c

has a few functions that take care of stripping whitespaces checking if the command is custom function or built in. If built in checks whether to execute in foreground or background.

  • childHandler.c

Has a killChild function that starts when a child process has completed successfully and has a kill all function that kills all paused childs in background on terminal exit.

  • pipeHandler.c

Has the code that handles pipes.

  • cd.c

Has code for changing directory.

  • echo.c

Has a code for echoing whatever is given (Ignores '"' and environment variables)

  • history.c

Functions that store the history max upto 20 in a file across sessions.

  • ls.c

Functions for listing all files and folder with/without hiddem with/without all details.

  • pwd.c

Function that prints current absolute dir

  • pinfo.c

Prints Process info given pid else prints the info of terminal

  • env.c

Has code for setenv and unsetenv

  • fgbg.c

Has code for fg bg and kjob

  • signalHandler

Handles signal interrupts ctrl+C and ctrl+Z

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published