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.
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>orkill -<SIGNAL> <PID>: Send a signal to a process.
- 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
- Input redirection:
- 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 indexnin history.
- GCC Compiler
- Make
To compile the shell, run:
makeTo clean build artifacts:
make cleanTo rebuild from scratch:
make rebuildStart the shell by running the executable:
./customshellThis shell has been fully checked for memory leaks using Valgrind
- Signal Handling: Uses
sigactionto handleSIGINT,SIGTSTP, andSIGCHLD. - Process Management: Uses
fork(),execvp(), andwaitpid()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.