Skip to content

YousefMoussa/CustomShell-C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Shell

Custom Shell is a simple custom shell implementation in C. It supports executing external commands, built-in commands, input/output redirection, piping, and job control.

Features

Built-in Commands

  • cd <directory>: Change the current working directory.
  • pwd: Print the current working directory.
  • exit: Terminate the shell and all child processes.
  • status: Display the exit status of the last executed command.
  • history: Show the list of previously executed commands.
  • jobs: List current background and suspended jobs with their PIDs and status.
  • fg <PID>: Bring a background or suspended job to the foreground.
  • bg <PID>: Resume a suspended job in the background.
  • kill <PID> or kill -<SIGNAL> <PID>: Send a signal to a process.

Shell Features

  • External Commands: Execute standard Linux commands (e.g., ls, ps, echo).
  • Piping (|): Chain commands together (e.g., ls -l | grep .c).
  • Redirection:
    • Input redirection: command < input_file
    • Output redirection (overwrite): command > output_file
    • Output redirection (append): command >> output_file
    • Error redirection: command 2> error_file
  • Background Processes: Run commands in the background using & (e.g., sleep 10 &).
  • Signal Handling:
    • Ctrl+C: Interrupt the foreground process.
    • Ctrl+Z: Suspend the foreground process.
  • Environment Variables: Access environment variables using $VAR (e.g., echo $HOME).
  • History Expansion:
    • !!: Re-execute the last command.
    • !n: Re-execute the command at index n in history.

Compilation and Usage

Prerequisites

  • GCC Compiler
  • Make

Building

To compile the shell, run:

make

To clean build artifacts:

make clean

To rebuild from scratch:

make rebuild

Running

Start the shell by running the executable:

./customshell

This shell has been fully checked for memory leaks using Valgrind

Implementation Details

  • Signal Handling: Uses sigaction to handle SIGINT, SIGTSTP, and SIGCHLD.
  • Process Management: Uses fork(), execvp(), and waitpid() for process creation and control.
  • Job Control: Maintains a linked list of Process Control Blocks (PCBs) to track background and suspended processes.
  • Tokenization: Custom tokenizer to handle command-line arguments and quotes.

About

Custom Shell is a simple custom shell implementation in C. It supports executing external commands, built-in commands, input/output redirection, piping, and job control.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors