Homework 2:

Short Description:

Explore a utility and write some error detecting code.

This assignment is worth 10 points.

Goals

When you finish this homework, you should

Formal Description

  1. Read chapters 2 and 3 of the book.
  2. Pick any one of the following unix utilities (awk, sed, grep, groff, diff, sort,bc), preferably one you are not familiar with. You may look at either unix or gnu versions of a utility. (awk or gawk for example)
    1. [2 points] Describe the purpose of this utility.
    2. [2 point] What problems could you solve with this utility?
    3. [1 point] Provide a "neat" example of this utility in action.
  3. [10 points] Write a program the performs the following tasks:
    1. Gets the process pid
    2. Gets and prints the processes current priority
    3. Changes processes priority to 10 higher
    4. Gets and prints the processes current priority
    5. Changes processes priority to 1
    6. Gets and prints the processes current priority
    7. Attempts to get and print the priority for process -1.
    8. Attempts to get and print the priority for process 1.
    This program should check for and report any errors encountered. It should print a message identifying the system call that failed along with the error that occurred. In addition the program should print the error number that occurred.

    Make sure that the program produces explicit output describing what it is attempting to do. Use plenty of blank lines. You probably should use plenty of comments in your code as well. Remember the purpose is to demonstrate your ability to detect errors and use error reporting routines.

    You should read the man page for getpriority/setpriority and for getpid. In addition the following code fragment should help.

    
    pid_t mypid
    int myprio
    
    mypid = getpid();  // no checking this can not fail.
    
    // perhaps you might want to check this...
    myprio = getpriority(PRIO_PROCESS, mypid);
    cout << "The priority for process " << mypid << " is " << myprio << "." << endl;
       
    I will compile your code with the following flags, it should produce no errors or warnings.
    -g -O3 -Wall -Wextra -Wuninitialized -pedantic -Wshadow -Weffc++ -std=c++14
       

Documentation

Your program should be well documented both with comments and self documenting code.

Submission

Type your answer to the first question and turn in a print out at the beginning of class on the due date. Send an email to dbennett@edinboro.edu with your code to the second part as an attachment.