PS-2: Interactive shell
Build an interactive C++ shell that spawns a process per command, adds the current directory to PATH, and redirects 'silent' commands to a PID.log file.
Requirements
- Write a C++ program that implements an interactive shell with an infinite loop waiting for a command.
- On every iteration of the loop a command string is passed to the shell program.
- A command can be either a name of command or a path (relative or absolute).
- After command is entered, program should create a new process to run the command.
- The current directory of the shell program should be temporarily added to the PATH variable of every new process.
- If "exit" command is entered, shell program should stop and exit with a success code.
- If entered command starts with word "silent", the executing command should redirect the standard output and error streams into the PID.log file where PID is the process id of the child process.
Expected result
The resulting application should be able to build and execute from command line as follows:
make
./interactive-shellUser may enter commands as follows:
lsor
/bin/lsor
./other-programand the command should print the output to the console.
Also user may want to enter commands as follows
silent ls -aland the output of program ls should be redirected into the file PID.log where PID is the identifier of the child process.
The final solution should contain a Makefile for the multi-stage build. The Makefile should also contain targets all and clean. It's recommended to have compiler and compiler flags declared as Makefile variables. Alternatively, cmake could also be used instead of make.
PS-1: Do command
Your task is to implement a C++ program that accepts a command name and command arguments with command-line arguments and executes it in a new process.
TH-1: Array Summary
Sum a large array in C++ with and without multithreading, taking array size and thread count from the command line, and compare the timings.