Advertisement
Guest User

Untitled

a guest
Jan 31st, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. CIS 3110: Operating Systems
  2. Assignment 1: Writing a Shell
  3. Due Date: Feb. 1, 2013
  4. The requirement
  5. In this assignment you are to implement a Unix shell program. A shell is simply a program that
  6. conveniently allows you to run other programs. Read up on your favorite shell to see what it does.
  7. The requirements for completing this assignment successfully are described under specification.
  8. You are provided with files called lex.c and myshell.c which contains some code that uses
  9. getline(), a function provided by lex.c to get and parse a line of input. getline() returns an array
  10. of pointers to character strings. Each string is either a word containing the letters, numbers, ., and
  11. /, or a single character string containing one of the special characters: ( ) < > | & ;.
  12. To compile lex.c, you have to use flex: "flex lex.c". This will produce a file called lex.yy.c.
  13. lex.yy.c and myshell.c must then be compiled and linked in order to get a running program. In
  14. the link step you also have to use "-lfl" to get everything to work properly. Use gcc for the
  15. compilation and linking.
  16. Specification
  17. (1) Your shell must support the following:
  18. 1. The internal shell command "exit" which terminates the shell.
  19. Concepts: shell commands, exiting the shell
  20. System calls: exit()
  21. 2. A command with no arguments
  22. Example: ls
  23. Details: Your shell must block until the command completes and, if the return code is
  24. abnormal, print out a message to that effect.
  25. Concepts: Forking a child process, waiting for it to complete, synchronous execution
  26. System calls: fork(), execvp(), exit(), wait()
  27. (2) Your shell can also support the following:
  28. 1. A command with arguments
  29. Example: ls -l
  30. Details: Argument 0 is the name of the command
  31. Concepts: Command-line parameters
  32. 2. A command, with or without arguments, executed in the background using &.
  33. For simplicity, assume that if present the & is always the last thing on the line.Example: xemacs &
  34. Details: In this case, your shell must execute the command and return immediately, not
  35. blocking until the command finishes.
  36. Concepts: Background execution, signals, signal handlers, processes, asynchronous
  37. execution
  38. System calls: sigset()
  39. 3. A command, with or without arguments, whose output is redirected to a file
  40. Example: ls -l > foo
  41. Details: This takes the output of the command and put it in the named file
  42. Concepts: File operations, output redirection
  43. System calls: freopen()
  44. 4. A command, with or without arguments, whose input is redirected from a file
  45. Example: sort < testfile
  46. Details: This takes the named file as input to the command
  47. Concepts: Input redirection, more file operations
  48. System calls: freopen()
  49. 5. A command, with or without arguments, whose output is piped to the input of
  50. another command.
  51. Example: ls -l | more
  52. Details: This takes the output of the first command and makes it the input to the second
  53. command
  54. Concepts: Pipes, synchronous operation
  55. System calls: pipe()
  56. (3) Your shell should implement the following new commands:
  57. 1. A command "add" that adds all numbers in command line (decimal or
  58. hexadecimal).
  59. Example: add 100 210 0xa
  60. Details: add all numbers and output the sum
  61. Output: 100 + 210 + 0xa = 320
  62. 2. A command "arg" that counts and lists command line arguments.
  63. Example: args 1 2 3 4 5 "six, seven"
  64. Details: count and list arguments
  65. Output: argc = 6, args = 1, 2, 3, 4, 5, "six, seven"
  66. 3. A command "???" that is named and designed by yourself.
  67. Example: you make an example
  68. Details: you specify the function
  69. Output: you give a sample output
  70. Note: You must check and correctly handle all return values. This means that you need to read
  71. the man pages for each function to figure out what the possible return values are, what errors
  72. they indicate, and what you must do when you get that error. Submission
  73.  If you have any problems in the development of your programs, contact the teaching
  74. assistant (TA) assigned to this course.
  75.  You are encouraged to discuss this project with fellow students. However, you are not
  76. allowed to share code with any student.
  77.  Each student should submit a brief report (2-3 paragraphs) that explains your algorithm,
  78. any assumptions you made, and the way to run your program.
  79.  If your TA is unable to run/test your program, you should present a demo arranged by
  80. your TA’s request.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement