联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2019-04-15 10:38

2019 Spring, CSCI 3150 – Assignment 1

Recommended Deadline: February 18, 2019

Deadline: April 25, 2019 11:00AM

Contents

1 Change Log 3

2 Introduction 3

2.1 Execution of any Linux program . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.2 Shell-specific commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.2.1 gofolder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.2.2 push,pop and dirs . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.2.3 bye . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.3 Basic signal handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.4 Basic command chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3 The Assignment Package 8

4 Your assignment 8

4.1 To begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4.2 Submitting your assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

1

5 Assumptions 10

6 Grading 10

7 Questions 11

8 Academic Honesty 12

9 General Notes 12

2

1 Change Log

1.0 This version

2 Introduction

In this assignment, you are going to implement a mini-shell, namely, asg1-shell, using C.

If one invokes the program asg1-shell, we shall see something like this:

Figure 1: Your shell

The prompt has the format of [3150 Shell:<current directory>]=>. Your shell shall

support:

Execution of any Linux built-in command (e.g., ls).

Five shell-specific commands: gofolder, push, pop, dirs and bye.

Basic signal handling: i.e., a user cannot exit the shell simply by typing ctrl-c.

Basic command chaining: && and k.

Basic error handling.

2.1 Execution of any Linux program

Your shell shall allow a user to execute any Linux program, with basic error handling. Note

that the user can input either an absolute path (e.g., /bin/ls) or just a filename (e.g.,

ls). If an absolute path is not given, your shell should search the program in the following

sequence:

3

/bin → /usr/bin → . (current directory)

In case your shell cannot locate the program, your shell should report an error message

“{command name}: command not found” (see Figure below).

*

2.2 Shell-specific commands

2.2.1 gofolder

This command is similar to cd command in Linux, for changing the working directory, like

below:

4

After a successful operation, your prompt shall be updated with current directory name.

Please note that you are just required to implement basic changing of directory as shown

above.

2.2.2 push,pop and dirs

These commands behave similarly to Linux commands pushd, popd, and dirs.

On push [directory path], the shell shall (1) push the current directory to a stack,

(2) change to the directory specified by [directory path], and (3) print the content

of the stack.

On dirs, the shell shall print the content of the stack. The format is:

[item number] [path]

With the most recent item starts with item number 0 and the oldest item in the stack

has the largest item number.

On pop, the shell shall (1) pop an item from the stack, (2) change to that directory

and (3) print the content of the stack.

If the end of the stack is reached, the shell should prompt the user:

pop: directory stack empty

Example:

5

2.2.3 bye

This command is equivalent to exit command in Linux, which lets a user to terminate the

shell (and back to the normal Linux bash shell).

2.3 Basic signal handling

Your shell shall handle the following list of signals as follow:

Signal Action

SIGINT (Ctrl + C) Ignore the signal.

SIGTERM (default signal of command “kill”) Ignore the signal.

SIGQUIT (Ctrl + \) Ignore the signal.

SIGTSTP (Ctrl + Z) Ignore the signal.

6

2.4 Basic command chaining

Your shell should handle two logical operations: AND(&&) and OR(k), like below:

7

3 The Assignment Package

You should have opened a Github account and told us your github account by filling up a

Google form during your assignment 0. So, after logging in your Github account, come here

https://classroom.github.com/a/KKQgMaHn to get a new repo for this assignment. The

new repo should contain the starter package for this assignment.

4 Your assignment

You are given the following files:

Name Description

/asg1-shell.c Source code of a runnable but non-functioning shell

(Work on it).

/asg1-shell Executable of a runnable but non-functioning shell.

(Try to run it; Type ctrl-d to quit)

/demo-asg1 Executable, serve as the demo of what you shall

implement. Our grading will also use this to define

test cases. That is, the behavior of your shell shall

exactly follow this demo.

/hello Executable, a hello world program.

/testcases/data Test data.

/Makefile Makefile to compile asg1-shell.

/grader.sh We will run this script to grade your assignment

(Don’t touch).

8

4.1 To begin

Make, then run grader.sh, you shall see something like this:

This shell script feeds in some test cases to asg1-shell (barely functioning, but you

should make it functioning in this assignment) and demo-asg1 (which is functioning, but no

source code is given) to match their outputs, and reports the number of test cases passed.

Initially, it shall report that none of the test cases passes. Your job is to make all test cases

pass:

If you invoke the grader script like the following:

./grader.sh 2

Then it only runs test case 2 for you.

9

4.2 Submitting your assignment

Follow the procedure in assignment 0.

5 Assumptions

You can assume the following always holds in this assignment:

Input

An input command line has a maximum length of 255 characters, including the trailing

newline character.

An input command line ends with a new line character \n

There would be no leading or trailing space characters in the input command line.

A token is a series of characters without any space character. Each token is separated

by exactly one space character only.

There will be no combination of shell commands in command chaining. For example,

no test cases like ls || bye, bye && bye, bye || ls are defined.

Your shell should also be terminated by ‘Ctrl-D’, the end-of-file character (NOT signal)

upon receiving in the prompt.

6 Grading

1. The TA will fetch and grade your latest version in your repo as of April 25, 2019,

11:00AM. Remember to commit and push before the deadline.

2. Your shell shall output results to standard output stream (stdout). Otherwise, you

will get 0 mark.

3. The objective of this assignment is to let you practice the necessary system programming

skills. So you are not allowed to do your assignment in a way that violates that

10

objective. Therefore, you cannot invoke system(3) library call, invoke any existing

shell programs, including but not limited to: “/bin/sh”, “/bin/bash”, “pushd”, calling

non built-in linux libraries and etc. Otherwise, you will score 0 mark. If you have

doubts about the legitimacy of your program, you may ask on Piazza.

4. Your shell should not leave any zombies in the system when it is ready to accept a new

user input. Otherwise, you will have 1 test case marks deducted.

5. There are 30 test cases in total. Test case 6 and test case 24 carry more weight – each

carries 6.25 mark. Each of the rest carries 3.125 mark.

6. Maximum assignment score is 100.

7. FAQ: Why the grader says a test case fails even if I test my shell under a terminal

without any problem?

Answer: This error usually appears if you forget to handle some error cases. In the

figure below, you can see a command ‘command not exists’ was fed to your shell.

This is a wrong command, therefore your shell cannot execute that and return to

the command prompt. One common case is that the child that handles the wrong

command still exists as exec*() fails. Therefore it is the child prompting you for

input instead of the parent. As the result, you need to bye twice in order to return to

the Linux shell. In this scenario, the grader will report a failed test case.

7 Questions

If you have doubts about the assignment, you are encouraged to ask questions on Piazza

using the corresponding tag. Please focus on knowledge. Unhealthy questions/comments

11

that focus on scores and grades are not encouraged.

If you find any (possible) bugs, send private questions on Piazza to us instead

— otherwise that may cause unnecessary panic among the class if that is not a real bug.

8 Academic Honesty

We follow the University guide on academic honesty against any plagiarism.

9 General Notes

This specification and our grading platform are both based our given course VM. You

should compile, debug and run the assignment program on that VM. So, if you insist

to develop on another platform other than our VM and got any question, test it on

our VM before you ask.

The TA reserves the right to adjust your scores for any request that requires their extra

manual effort.

Unless specified, you should work and fill your code in designated areas. There are

cases that the modification outside the designated area leads to misbehavior of the auto

grader. Proceed with caution and look back the changes if your output is different from

what is shown in the grader.

While we have already tried our best to prepare this assignment, we reserve all the

rights to update the specification and the grading scheme. If there are any mistakes/bugs

which are on ours, the TA will step in and do manual grading to ensure

you get what you deserve. Please respect each other. Any irresponsible, unfair, biased

sentiment would regard as a disciplinary case.

If this is a programming assignment, only C is allowed, not even C++. If this is a

scripting assignment, only bash shell script is allowed, not even Python. Furthermore,

for C programming assignments, use the “exit” function parsimoniously because it

might influence the grader as well. Therefore, use “return” instead of “exit” whenever

possible.

12

Although this is not an algorithm class, you still shouldn’t implement your assignment

with very poor complexity. While the TAs will try their best to run your program

as long as they could, they reserve the right to terminate a test case and regard that

as a failed test case when a program takes unreasonably long time to finish (try to

compare your running time with the TA’s demo if it is given), or until when the TAs

can’t run any longer due to the deadline the TA needs to submit your final scores to

the department.

When grading, the TAs will execute the grader program to run the whole test suite

(which consists of all test cases). The TAs won’t grade each individual test case

separately.

(Frequently Asked) [Output format] If the assignment package includes a demo,

then our grader defines test cases based on the given demo. In that case, your output

shall exactly follow that demo. For example, hypothetically, if our demo outputs a

message like:

command not found

with two spaces between “not” and “found”. Your output shall also match that in

order to pass the test. The good news is that, if our given demo has not implemented

something (e.g., missed certain error checking), you also don’t need to do so. No

test cases would be defined based on something that our demo has not

implemented.

(Frequently Asked) [Scope of error handling] The scope of error checking and

handling shall refer to both our given demo (if given) and our given test cases.

First, the corresponding output message shall exactly follow our demo. Second, you

are informed that our demo may have implemented more error checking that what our

grader will test. In that case, it is fine that you implement only the error checking that

is tested by our grader. So, one top tip is:

CHECK THE (SOURCE OF)

13

TEST CASES BEFORE YOU ASK

(Frequently Asked) [No hidden test case] We are not intended to run any secret/extra

test cases that deliberately break your assignment. That is, WYSIWYG — your

final score shall be generally indicated by what the grader reports when it runs on

the course VM. However, we do reserve the right to run some additional test cases to

avoid any mis-conduct (e.g., hard-coding the results), and/or invite you to explain the

source code to the teaching assistants and adjust the scores accordingly.

We welcome discussions among classmates. But don’t share your assignment with the

others in any means. For example, don’t put your source code in any public venue (e.g,

public repo, your homepage, Facebook). We handle plagiarism strictly. On submitting

this assignment, you are agreed that your code’s copyright belongs to the Chinese

University of Hong Kong. Unless with our written approval, you must not release

your source code and this specification now and forever. If you share your code with

anyone without our written consent, that would regard as a disciplinary case as long

as you are still a CUHK student (i.e., even after this course). If you share your code

with anyone without our written consent after your graduation, that would regard as

a breach of copyright and we reserve all the rights to take the corresponding legal

actions.

Google is your friend. We encourage you use Google for help to do the assignment.

However, if you happen to find any source codes related to this assignment, you still

cannot copy it but use your own way to implement it. You need to put down your list

of source code references as comments in the top of your source code.

(Frequently Asked) [Late Policy] TAs will only grade the latest version submitted

before the deadline, no late submission is allowed. It is your responsibility to make

sure you added, committed, and pushed the final version before the deadline. You are

required to check whether your final version is really in Github Classroom.

14


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp