2022 Spring Semester System Programming Lecture Project
This shell simply takes the command from user and runs it. But, some commands like cd
don't work.
In this program, generally, the following system calls were used
- fork system call → creates a new processes
- exec family functions → to replace the current running process with the new process
- pipe → to provide communication between processes
- wait → to synchronize parent and child processes
- dup, dup2 → to direct std_out stream to pipes
You need linux environment and the packages.
In Debian/Ubuntu, To install the packages type
sudo apt install build-essential
Then change directory to the folder where you download this project and type make
then ./shell
and you're ready.
- Print ">>"
- Fetch the command from user
- Try to find the command in the system
- To find the command, create pipe which is going to be used for communication between processes by using
pipe
system call and create child process byfork
system call - In the child process, direct std_out to pipe with the help of
dup2
system call and then pass the command entered by the user toexecl
function with whereis argument. Thus, output is written to pipe. - In the parent process, read pipe
- If the command is not found, then print "commandName : not found"
- If the command is found, to run the command
- create a new process and then pass the command and its arguments to execv system call. After run the command, turn step 1.