Embedded Linux Minishell Project
Embedded Linux Minishell Project
Project Brief
Mini Shell is a Command Line Interface to accept and execute custom commands from the user. The goal of this embedded linux minishell project is to port the application into an ARM based Embedded Target.
About this project
TYPE | Individual project |
DIFFICULTY | Advanced |
ESTIMATED TIME | 80 hours |
CONTACT | training@emertxe.com |
Introduction
Port the mini-shell (msh) which was implemented as part of the Linux Internal module. The objective is to understand and use our application liked as init and understand the system calls w.r.t process creation, signal handling, process synchronization, exit status, text parsing etc..
Requirement Details
Provide a prompt for the user to enter commands
- Display the default prompt as msh>
- Prompt should be customizable using environmental variable PS1
- To change the prompt user will do PS1=NEW_PROMPT
- Make sure that you do not allow whitespaces between =,
i.e., do not allow PS1 = NEW_PROMPT - In the above case, it should be treated like a normal command
Execute the command entered by the user
- User will enter a command to execute
- If it is an external command
- Create a child process and execute the command
- Parent should wait for the child to complete
- Only on completion, msh prompt should be displayed
- If user entering without a command should show the prompt again
Special Variables:
- Exit status of the last command (echo $?)
- After executing a command the exit status should be available
- echo $? should print the exit status of the last command executed
- PID of msh (echo $$)
echo $$: should print mshโs PID - Shell name (echo $SHELL)
echo $SHELL: should print msh executable path
Signal handling
Provide short cuts to send signals to running program
- Ctrl-C (Send SIGINT), On pressing Ctrl-C
- If a programming is running in foreground, send SIGINT to the program (child process)
- If no foreground program exists, re-display the msh prompt โฆ Ctrl+z (Send SIGSTP), On pressing
- Ctrl+z (Send SIGSTP), On pressing Ctrl+z
- The program running in foreground, should stop the program and parent will display pid of child
- The program running in foreground, should stop the program and parent will display pid of child
Built-in commands
- exit โ This command will terminate the msh program
- cd โ Change directory
- pwd โ show the current working directory
Background Process / Job control
- Allow a program to run in background
- To run a program in background use ampersand (&) after the command. For eg: sleep 50 &
- Implement fg, bg and jobs commands
- bg will will move a stopped process to background sleep 10 & is equivalent to sleep 10 then ctrl + z and bg.
- After this the msh prompt should be displayed indicating it is ready to accept further commands. After a bg process ends, cleanup the process using wait.
- NOTE: You may have to use SIGCHLD signal handler for this
- On termination of bg process, display its exit status. User should be able to run any number of background processes.
- fg will bring a background process to foreground. Only fg bring last background process, or fg will bring given pid to foreground.
- jobs will print all background process details.
- bg will will move a stopped process to background sleep 10 & is equivalent to sleep 10 then ctrl + z and bg.
Pipe functionality
- Allow multiple processes communication by using pipes.
- Create pipes and childs dynamically as per pipes passed from command-line
Eg: ls | wc, ls -l /dev | grep tty | wc -l
- Exit status of the last command (echo $?)
Skeleton Code
The skeleton code is a very interesting concept used in Emertxe. By looking into the skeleton code, you will get a clear picture of converting the given requirement into a working embedded linux minishell project solution. This will also take care of important aspects like modularity, clean coding practices, reusability, etc.
Sample Output
Here are the sample output expected by the end of project execution.
Fig1: Basic Functions
Fig2: Shell Functions
Fig3: Basic Commands
Fig4: Signal Handling
Fig5: Background and Foreground control
Fig6: Pipe Function
- Special Variables:
- Signal handling
- Built-in commands
- Background Process / Job control
- Pipe functionality
- Special Variables:
- Signal handling
- Built-in commands
- Background Process / Job control
- Pipe functionality