Program Execution
Before we start implementing launching programs, the first task is to modify the existing built-in exit
command.
Add support for an additional numeric argument to the built-in
exit
command. If this argument is provided it will be interpreted as a number and used as the exit code passed to theexit()
syscall. If the argument is left off, then zero0
should be used as the exit code.You may want to read about
strtol
to convert a string (the argument) to an integral value. We would advise against usingatoi
for this purpose as this function does not allow to properly diagnose conversion errors.
If you try to type something into your shell that isn’t a built-in command, you’ll get a message that the shell doesn’t know how to execute programs.
Modify your shell so that it can execute programs when they are entered into the shell. The first word of the command is the name of the program. The rest of the words are the command-line arguments to the program.
At this point, you can assume that the first word of the command will be the full path to the program. So instead of running wc
, you would have to run /usr/bin/wc
. In the following parts, you will implement support for simple program names like wc
(i.e. commands that don’t have their full path specified). However, you can pass some autograder tests by only supporting full paths.
You should use the functions given in src/tokenizer.h
for separating the input text into words. You do not need to support any parsing features that are not supported by src/tokenizer.h
. When your shell needs to execute a program, it should fork
a child process, which calls one of the functions from the exec
family to run the new program. You may not use execvp
(see Path Resolution). The parent process should wait until the child process completes and then continue listening for more commands.
Once you implement this functionality, you should be able to execute programs.
Next up: read about Path Resolution.