Question: Minishell Description: Implement a minimalistic shell, mini - shell ( msh ) as part of the Linux Internal module. Objective: The objective is to understand
Minishell
Description:
Implement a minimalistic shell, minishellmsh as part of the Linux Internal module.
Objective:
The objective is to understand and use the system calls wrt 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 PS
To change the prompt user will do PSNEWPROMPT
Make sure that you do not allow whitespaces between ie do not allow PS NEWPROMPT
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 mshs PID
Shell name echo $SHELL
echo $SHELL: should print msh executable path
Signal handling
Provide shortcuts to send signals to running program
CtrlC Send SIGINT
On pressing CtrlC
If a programming is running in foreground, send SIGINT to the program child process
If no foreground program exists, redisplay the msh prompt Ctrlz Send SIGSTP
Ctrlz Send SIGTSTP
On pressing Ctrlz
The program running in foreground, should stop the program and parent will display pid of child
Builtin commands
exit exit: This command will terminate the msh program
cd 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 &
Implement fg bg and jobs commands
bg will will move a stopped process to background sleep & is equallent to sleep then ctrl z and bg
After this the msh prompt should be displayed indicating it is readyto 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.
Pipe functionality
Allow multiple processes communication by using pipes.
Create pipes and childs dynamically as per pipes passed from commandline
Eg: ls wc ls l dev grep tty wc lgive the code for this please help please with the code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
