Description
This assignment may be completed idividually or in a group (up to three people).
1 Ov erview
In this assignment, you will develop a simple Linux shell. The shell accepts user commands and then executes each command in a separate process. The shell provides the user a prompt at which the next command is entered. One technique for implementing a shell interface is to have the parent process first read what the user enters on the command line and then create a separate child process that performs the command. Unless otherwise specified, the parent process waits for the child to exit before continuing. However, UNIX shells typically also allow the child process to run in the background – or concurrently – as well by specifying the ampersand (&) at the end of the command. The separate child process is created using the fork() system call and the user’s command is executed by using one of the system calls in the xec() () family.
As usual, all code be written in C and run on a Linux machine. We will grade your code on a Linux machine. You should create a directory for this assignment, such as ~/cmpt30/a1/ and put all files related to this assignment in it.
2. A Simple Shell
A C program that provides the basic operation of a command line shell is given below. The main() function first calls recomand() command( , which reads a full command from the user and tokenizes it into separate words (arguments). These tokens can be passed directly to xecvp() () in the child process. If the user enters an “&” as the final argument, recomand() will set the bcoudkgrani parameter to true (and remove the “&” from the array of tokens). For example, if the user enters “ls -l” at the ‘$’ prompt, tokens[0] [ 0] will contain “ls”, tokens[1] [ 11 will contain (or point to) the string “-l”, and tokens[2] [2] will be a NUL pointer indicating the end of the arguments. (Each of these strings is a NUL terminated C-style string). Note that the character array buf will contain the text that the user entered; however, it will not be one single NUL terminated string but rather a bunch of NUL terminated strings, each of which is a token pointed to by the tokens array.
# <stdio.h> # <stdbol.h> # <stdlib.h> # <string.h> # <unistd.h>
# MAN COMMAND LENGTH 2041 # MN NUM TOKENS ( COMADLENGTH LENGTH / 2 + 1 )
https://systems.cs.sfu.ca/cmpt300/spring21/assignments/a1/a1.html .htnil 1/8


