Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Project 2 – Unix Utility

CSCI 1730 – Fall 2021


Project Description

This project may be completed individually, or in groups of two. If you decide to work in a group, please first review the group work policy in the syllabus. Only one member from the group should submit the project. Please do not have both members of the group submit the same project.

For this project, you are tasked with implementing a collection of basic Unix utilities using low-level system calls. Not all utilities are the same difficulty. Please start early and manage your time wisely.

Hint: if you are ever unsure what the expected behaviors of your programs should be, then you should mimic the behaviors of the corresponding utilities programs on odin. For example, your head program should work the same way as odin’s head program when given the same options and arguments; but note that odin’s head program does support a lot more options than what you will be required to implement.

Here is the list of utilities that you must implement. For head, tail, and wc, you may also assume that each of the input files will be less than 1 MB in size.

1. ./head [ -c number | -n number] [files...]

    ./tail [ -c number | -n number] [files...]

(40 points) The head and tail utilities should copy their input files to the standard output, ending or starting the output for each file at a designated point, respectively. Copying must end/begin at the point in each input file indicated by the -c number or -n number option. The option-argument number is counted in units of lines or bytes, according to the options -n and -c, respectively. Both line and byte counts start from 1. If no options are specified, act as if -n 10 had been specified. If no files operand is specified, or when one of the files is -, then standard input is assumed.

-n number: The first (head) or last (tail) number lines of each input file to be copied to standard output. The application must ensure that the number option-argument is a positive decimal integer. When a file contains less than number lines, it must be copied to standard output in its entirety. This should not be an error.

-c number: Output the first (head) or last (tail) number of bytes. A positive decimal integer as well.


2. ./wc [-clw] [files...]

(40 points) The wc utility should read one or more input files and, by default, write the number of newlines, words, and bytes, in that order, contained in each input file to the standard output (in other words, the default behavior matches having the options -clw). The utility should also write a total count for all named files, if more than one input file is specified. The wc utility should consider a word to be a non-zero-length string of characters delimited by whitespace characters. Your program should be able to handle any combinations of the -c, -l and -w, in any order (e.g, ./wc -wl -c). If no files operand is specified, or when one of the files is -, then standard input is assumed.

-c: Write to the standard output the number of bytes in each input file.

-l: Write to the standard output the number of newlines in each input file.

-w: Write to the standard output the number of words in each input file.


3. ./true

    ./false

(10 points) The true utility shall return with exit code EXIT_SUCCESS. The false utility shall return with exit code EXIT_FAILURE.


4. ./env

(10 points) The env utility prints all of the currently set environmental variables to standard output.


Nonfunctional Requirements

Your submission needs to satisfy the following nonfunctional requirements:

Directory Setup: If you work individually, then make sure that all of your files are in a directory called LastName-FirstName-p2, where LastName and FirstName are replaced with your actual last name and first name. If you work in a group, then the directory should be named LastName1-FirstName1-LastName2-FirstName2-p2, so that the names of both members of the group are there.

 Libraries: You are allowed to use any of the C standard libraries, but with the following restrictions: When reading or writing to a file are concerned, you need to use low-level calls to read(2) and write(2) and related functions. Whenever possible, program output should be unbuffered. You are NOT allowed to use the following system calls in any of your implementations: fork(2), execve(2), exec(3), popen(3), and system(3) (and related functions). Failure to adhere to this non-functional requirement will cause you to earn no points for the utility programs(s) in which these forbidden system calls/functions are used.

 Documentations: Your code must be documented using Javadoc style comments. Use inline documentation, as needed, to explain ambiguous or tricky parts of your code. A maximum of 5 points will be deducted for not including appropriate documentations.

 makefile: You need to include a makefile. The resulting executable names should correspond to the ones presented in the previous section. The very first target in your makefile should produce executables for all the utility programs. Please also include a ‘clean’ target to remove any object code and executables. The expectation is that the grader should be able to type make clean and make to clean and compile/link your submission, respectively. A maximum of 5 points will be deducted for a bad/missing makefile.

 Standards & Flags: Make sure that when you compile, you pass the following options to gcc:

-Wall -pedantic-errors

Other compiler/linker options may be needed in addition to the ones mentioned above.

README File: Make sure to include a README file that includes the following information presented in a reasonably formatted way:

– Your Name and UGA ID (811#), as well as your teammate’s info, if applicable.

– Instructions on how to compile and run your program.

– Each group member’s detailed contributions to this project, if applicable.

A maximum of 5 points will be deducted for an README file that does not adhere to these standards.

Compiler Warnings: Since you should be compiling with both the -Wall and -pedantic-errors options, your code is expected to compile without gcc issuing any warnings. Failure to adhere to this non-functional requirement will result in an automatic 5 point deduction.

Memory Leaks: Since this project may make use of dynamic memory allocation, you are expected to ensure that your project implementation does not result in any memory leaks. We will test for memory leaks using the valgrind utility. Failure to adhere to this non-functional requirement will result in an automatic 5 point deduction.


Submission

Before the due date, you need to submit your code via odin. Make sure your work is on odin.cs.uga.edu in a directory called LastName-FirstName-p2, or LastName1-FirstName1-LastName2-FirstName2-p2 if you worked in a group. From within the parent directory, execute one of the following commands:

$ submit LastName-FirstName-p2 csci-1730

or

$ submit LastName1-FirstName1-LastName2-FirstName2-p2 csci-1730