SOLVED:CSCI 340, Project 2a (Fork/exec) and 2b (Signal handling, Unix Shell)

40.00 $

Category: Tags: , , , , , , , , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: rar solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (6 votes)

SOLVED:CSCI 340, Spring 2013 Project 2a (Fork/exec) and 2b (Signal handling, Unix Shell)
2 Introduction The purpose of this assignment is to become more familiar with the concepts of process control and signaling. You’ll do this by writing a simple Unix shell program that supports job control. This assignment is based on a similar assignment developed by Anderson and Dahlin. 3 Logistics You may work in a group of two people in solving the problems for this assignment. Your solutions will be submitted electronically using the submit script discussed in class. Clarifications to the assignment will be provided in class. Revisions will be posted to the CSCI 340 course Web page. Note: This project will be graded on stono. Although you are welcome to do testing and development on any platform you like, I do not have the time to assist you in setting up other environments. You must test and do final debugging on stono. The statement, “Well, it worked on my machine” will not be considered in the grading process. 4 Instructions The provided file, shlab-starter.tar contains a template for your program along with a number of useful helper functions. Get it from the course Web page: $ wget http://www.cs.cofc.edu/~leclerc/340/shlab-starter.tar Put the file shlab-starter.tar in a properly named project 2a directory. Then type the following commands in order: $ tar xvf shlab-starter.tar $ make The tar command will extract the tarfile and the make command will compile and link some test routines. Now, edit the file, README and enter your team member names at the top of the file. Looking at the file, tsh.c (tiny shell), you will see that it contains a functional “skeleton” of a simple Unix shell. To help you get started, the less interesting functions have already been implemented. Your assignment is to complete the remaining empty functions listed below. As a “sanity check”, the approximate number of lines of code for each of these functions is listed in the reference solution (which includes lots of comments). • eval: Main routine that parses and interprets the command line. [70 lines] • builtin cmd: Recognizes and interprets the built-in commands: quit, fg, bg, and jobs. [25 lines] • do bgfg: Implements the bg and fg built-in commands. [50 lines] • waitfg: Waits for a foreground job to complete. [20 lines] • sigchld handler: Catches SIGCHILD signals. [80 lines] • sigint handler: Catches SIGINT (ctrl-c) signals. [15 lines] • sigtstp handler: Catches SIGTSTP (ctrl-z) signals. [15 lines] Each time you modify the file tsh.c, type make to recompile and link it. To run your shell, type on the command line: $ ./tsh tsh [type commands to your shell here] 5 General Overview of Unix Shells A shell is an interactive command-line interpreter that runs programs on behalf of the user. A shell repeatedly prints a prompt, waits for a command line on stdin, and then carries out some action, as directed by the contents of the command line. The command line is a sequence of ASCII text words delimited by whitespace. The first word in the command line is either the name of a built-in command or the pathname of an executable file. The remaining words are command-line arguments. If the first word is a built-in command, the shell immediately executes the command in the current process. Otherwise, the word is assumed to be the pathname of an executable program. In this case, the shell forks a child process, then loads and runs the program in the context of the child. The child processes created as a result of interpreting a single command line are known collectively as a job. In general, a job can consist of multiple child processes connected by Unix pipes. If the command line ends with an ampersand “&”, then the job runs in the background, which means that the shell does not wait for the job to terminate before printing the prompt and awaiting the next command line. Otherwise, the job runs in the foreground, which means that the shell waits for the job to terminate before awaiting the next command line. Thus, at any point in time, at most one job can be running in the foreground. However, any number of jobs can run in the background. For example, typing the command line tsh jobs causes the shell to execute the built-in jobs command. Typing the command line tsh /bin/ls -l – d runs the ls program in the foreground. By convention, the shell ensures that when the program begins executing its main routine int main(int argc, char *argv[]) the argc and argv arguments have the following values: • argc == 3 , • argv[0] == “/bin/ls” • argv[1]== “-l” • argv[2]== “-d” Alternatively, typing the command line tsh /bin/ls -l -d & runs the ls program in the background. Unix shells support the notion of job control, which allows users to move jobs back and forth between background and foreground, and to change the process state (running, stopped, or terminated) of the processes in a job. Typing ctrl-c causes a SIGINT signal to be delivered to each process in the foreground job. The default action for SIGINT is to terminate the process. Similarly, typing ctrl-z causes a SIGTSTP signal to be delivered to each process in the foreground job. The default action for SIGTSTP is to place a process in the stopped state, where it remains until it is awakened by the receipt of a SIGCONT signal. Unix shells also provide various built-in commands that support job control. For example: • jobs: List the running and stopped background jobs • bg

  • Project2-1.rar