Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All programming done in xv6. Please submit source code in file head.c and provide screenshots. Write a program that prints the first 10 lines of

All programming done in xv6. Please submit source code in file head.c and provide screenshots.

Write a program that prints the first 10 lines of its input. If a filename is provided on the command line (i.e., head FILE) then head should open it, read and print the first 10 lines, and then close it. If no filename is provided, head should read from standard input.

image text in transcribedYou 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 head :

image text in transcribedThe above command searches for all instances of the word the in the file README , and then prints the first 10 matching lines.

Hints:

1. Many aspects of this are similar to the wc 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.

The traditional UNIX head utility can print out a configurable number of lines from the start of a file. Implement this behavior in your version of head . The number of lines to be printed should be specified via a command line argument as head -NUM FILE, for example head -3 README to print the first 3 lines of the file README. The expected output of that command is:

image text in transcribed

If the number of lines is not given (i.e., if the first argument does not start with - ), the number of lines to be printed should default to 10 as in the previous part.

Hints:

  1. You can convert a string to an integer with the atoi function.

  2. You may want to use pointer arithmetic (discussed in class in Lecture 2) to get a string

    suitable for passing to atoi.

$ head README xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix Version 6 (v6). xv6 loosely follows the structure and style of v6, but is implemented for a modern x86-based multiprocessor using ANSI ACKNOWLEDGMENTS xv6 is inspired by John Lions's Commentary on UNIX 6th Edition (Peer to Peer Communications; ISBN: 1-57398-013-7; 1st edition (June 14 2000)). See also http://pdos.csail.mit.edu/6.828/2014/xv6.html, which provides pointers to on-1ine resources for v6. $ grep the README I head Version 6 (v6). xv6 loosely follows the structure and style of v6, xv6 borrows code from the following sources: JOS (asm.h, elf.h, mmu.h, bootasm.S, ide.c, console.c, and others) Plan 9 (entryother.s, mp . h, mp . c, .c) In addition, we are grateful for the bug reports and patches contributed by The code in the files that constitute xv6 is To run xv6, install the QEMU PC simulators. To run in QEMU, run "make gemu" To create a typeset version of the code, run "make xv6.pdf". This requires the "mpage" utility. See http://www.mesa.n1/pub/mpage/ $ head-3 README xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix Version 6 (v6). xv6 loosely follows the structure and style of v6, but is implemented for a modern x86-based multiprocessor using ANST

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions