[Solved] CSGY6233-Homework 1

$25

File Name: CSGY6233-Homework_1.zip
File Size: 178.98 KB

SKU: [Solved] CSGY6233-Homework 1 Category: Tag:
5/5 - (1 vote)

In this assignment, youll start getting familiar with xv6 by writing a couple simple programs that run in the xv6 OS.

As a prerequisite, make sure that you have done the hello demo in Anubis to familiarize yourself with Anubis and xv6

A common theme of the homework assignments is that well start owith xv6, and then add something or modify it in some way. This assignment is no exception.

Make sure you can build and run xv6. To build the OS, run make to compile xv6:

$ make

Then, to run it inside of QEMU, you can do:

$ make qemu

QEMU should appear and show the xv6 command prompt, where you can run programs inside xv6. It will look something like:

Figure 1: Starting xv6 in QEMU

You can play around with running commands such as ls, cat, etc. by typing them into the QEMU window; for example, this is what it looks like when you run ls in xv6:

Figure 2: Running ls in xv6

Part 2: Implementing the uniq command

For this assignment you will be creating commonly used command line program in Linux called uniq but will be implementing this yourself in xv6 to get an idea of how command line programs are written.

uniq is a Unix utility which, when fed a text file, outputs the file with adjacent identical lines collapsed to one. If a filename is provided on the command line (i.e., uniq FILE) then uniq should open it, read, filter out, print without repeated lines in this file, and then close it. If no filename is provided, uniq should read from standard input.

For this assignment you will be running the uniq command on the README.md file included in xv6. Before you begin coding please delete all the text in README file and paste the following lines of text in the README.md file in its place. This is the file and subsequent text you will be running the uniq program on.

Text to copy and paste into xv6 README.md file:

No. 1

No. 2

No. 2

No. 2

No. 3

No. 4

No. 5

No. 6

No. 6 No. 2 no. 2

Now that you have set up your test file you may begin coding by creating a uniq.c file and coding your program there.

Heres an example of the basic usage of uniq:

$ cat README.md

No. 1

No. 2

No. 2

No. 2

No. 3

No. 4

No. 5

No. 6

No. 6 No. 2 no. 2

$ uniq README.md

No. 1

No. 2

No. 3

No. 4

No. 5

No. 6

No. 2 no. 2

You should also be able to invoke it without a file, and have it read from standard input. For example, you can use a pipe to direct the output of another xv6 command into uniq:

$ cat README.md | uniq

No. 1

No. 2

No. 3

No. 4

No. 5

No. 6 No. 2 no. 2

Hints

  1. Many aspects of this are similar to the wc.c program: both can read from standard input if no arguments are passed or read from a file if one is given on the command line. Reading its code will help you if you get stuck.
  1. Still confused with uniqs behavior? Use man uniq for help.
  1. The following link should help give you an idea on how to parse command line arguments and fetch them from the main function : https://dev-notes.eu/2018/03/parse-command-line-arguments-in-c/

Part 3: Extending uniq

The traditional UNIX uniq utility can do lots of things, such as:

  • -c: count and group prefix lines by the number of occurrences
  • -d: only print duplicate lines
  • -i: ignore dierences in case when comparing

Here, we are going to implement these three behaviors in your version of uniq. The expected output of these commands should be:

$ uniq -c README.md

1 No. 1

3 No. 2

1 No. 3

1 No. 4

1 No. 5

2 No. 6

1 No. 2

1 no. 2

$ uniq -d README.md

No. 2

No. 6

$ uniq -i README.md

No. 1

No. 2

No. 3

No. 4

No. 5

No. 6

No. 2

$ uniq -c -i README.md

1 No. 1

3 No. 2

1 No. 3

1 No. 4

  • 5
  • 6

2 No. 2

Notice that No. 2 should be the same as no. 2 if uniq is not case-sensitive. Also, -c and -d wont appear at the same time.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSGY6233-Homework 1
$25