Phone:

+(886) 909 756 966

Email:
moneychien20639@gmail.com

© 2024 Yu-Hang

Course:

Introduction to Computer Systems (15-513)

Time Spent:

30 hours

Source Code:
to github

Shell Lab

This tiny shell program (tsh) is designed to replicate a minimalistic shell interface. It allows users to execute commands, manage background and foreground jobs, and handle various signals such as SIGINT, SIGTSTP, and SIGCHLD. The shell supports built-in commands like 'jobs', 'bg', and 'fg', which help in controlling job states and displaying job lists. The shell uses data structures like job lists to keep track of all running jobs and their states. It employs signal handling to manage job control and ensure smooth execution of foreground and background tasks. The implementation includes functionalities to handle input/output redirection and execute external commands using the fork and execve system calls.

Features Implemented:
- Command Execution: The shell can execute commands with arguments and environment variables.
- Job Control: Supports foreground and background jobs, controlled by built-in commands like jobs, bg, and fg.
- Signal Handling: Handles various signals such as SIGINT, SIGTSTP, and SIGCHLD for job control and cleanup.
- Input/Output Redirection: Implements I/O redirection using the dup2 system call.
- Built-in Commands: Includes commands like quit, jobs, bg, and fg.

Key Functions:
- eval: Parses and evaluates the command line input, handles built-in commands, and executes external commands with appropriate redirections.
- sigchld_handler: Handles SIGCHLD signals to reap terminated or stopped child processes.
- sigint_handler: Handles SIGINT signals to terminate the foreground job.
- sigtstp_handler: Handles SIGTSTP signals to stop the foreground job.
- builtin_command: Processes built-in commands and takes necessary actions.
- wait_fg: Waits for a foreground job to complete.


  • C
  • Shell Programming
  • Process Control
  • Job Management
  • Signal Handling
  • Linux System Calls
  • I/O Redirection
  • Error Handling
  • Systems Programming