Operating System Experiment Project
Linux System Calls
Purpose
The main goals for this project are to familiarize you with the Linux operating system—how it works, how to use it, and how to compile code for it and to give you an opportunity to learn how to use system calls. To do this, you're going to implement a Unix shell program. A shell is simply a program that conveniently allows you to run other programss.
Basics
You should read over the Linux website before you start this project. In it, you'll find valuable information about the Linux operating system and the x86 emulators available to run it as well as general guidelines and hints for projects in this class. Before going on to the rest of the assignment, get Linux running in your choice of emulator.
You are provided with the files shell.l and myshell.c that contain some code that calls getline(), a function provided by shell.l to read and parse a line of input. The getline() function returns an array of pointers to character strings. Each string is either a word containing the letters, numbers, period (.), and forward slash (/), or a character string containing one of the special characters: ( ) < > | & ; (these all have syntactical meaning to the shell).
To compile shell.l, you have to use the lex command in Linux. This will produce a file called lex.yy.c. You must them compile and link lex.yy.c and myshell.c in order to get a running program. In the link step, you also have to use -L/usr/lib -lfl to get everything to work properly. Use cc for compiling and linking.
Details
Your shell must support the following:
The internal shell command exit which terminates the shell.
Concepts: shell commands, exiting the shell
System calls: exit()
A command with no arguments.
Example: ls
Details: Your shell must block until the command completes and, if the return code is abnormal, print out a
message to that effect. This holds for all command strings in this assignment.
Concepts: Forking a child process, waiting for it to complete, synchronous execution.
System calls: fork(), execvp(), exit(), wait()
A command with arguments.
Example: ls -l
Details: Argument zero is the name of the command other arguments follow in sequence.
Concepts: Command-line parameters.
A command, with or without arguments, whose output is redirected to a file.
Example: ls -l > file
Details: This takes the output of the command and puts it in the named file.
Concepts: File operations, output redirection.
System calls: close(), dup()
A command, with or without arguments, whose input is redirected from a file.
Example: sort < scores
Details: This uses the named file as input to the command.
Concepts: Input redirection, file operations.
System calls: close(), dup()
A command, with or without arguments, whose output is piped to the input of another command.
Example: ls -l | more
Details: This takes the output of the first command and makes it the input to the second command.
Concepts: Pipes, synchronous operation
System calls: pipe(), close(), dup()

