CS384: UNIX System Calls



->Courses
-->CS384
-->Paper
->Lab 1
-->Lab 2
-->Lab 3
-->Lab 4
-->Lab 5
->Electronic Submission
->Old Exams
->C++ Examples
->Software
->Tentative Schedule
->Support Forum
->Course Policies

[Courses]
[Rich][Home][Rich]
[Author]

Winter 2002-2003

Acknowledgement

This assignment was developed by Dr. Mark Sebern.

Overview

The purpose of this lab is to review the C++ programming environment on the UNIX (Linux) operating system and to make use of some simple operating system calls.

Prerequisite Assumptions

It is assumed that you are familiar (e.g., from CS-321) with building C++ programs in the UNIX environment. If not, ask the instructor for assistance. Reference information on make files is located here.

Lab Activity

First, implement the following C++ classes (each with separate ".cpp" and ".h" files):

  • Program information class. This class will have only static member functions, one to perform each of the following tasks:
    • Return a C++ string (not a C-style character string) containing the system node name and the current user name in the form "sebern@defiant.msoe.edu". Use the system calls uname, getuid, and getpwuid or getpwuid_r (why would you choose one over the other?) to implement the function; see the man pages for more information. (When using "man", note that you may have to specify a section number, such as "2" for system calls, if the item you are looking up has entries in more than one section.)
    • Return a C++ string containing the current time in the form "Monday, November 25, 2002, 03:30 PM". Use the time system call and related system functions.
    • Return a C++ string containing the process ID's of the current process and its parent, in the form "12345:34567". Use the system calls getpid and getppid.
  • System command class. This class should have the following members:
    • A C++ string data member to hold a command string to be executed.
    • A data member of appropriate type to hold the return "status" value from the system system call (see below).
    • A no-argument constructor.
    • A copy constructor.
    • A destructor.
    • A copy-assignment operator.
    • An accessor and a mutator for the "command string" data member.
    • A function to run the command specified by the "command string" data member, using the system system call. (A more sophisticated way of doing the same thing will be covered later.) The status value should be stored in the "status" data member.
    • An accessor for the "status" data member, to return the status of the most recently executed command.

Write a test program ("main" function, in a separate ".cpp" file) to call the functions and to print the data returned by each. Create a make file to build the test program properly.

If you have time, try setting up a common directory tree in the account of your team's appointed librarian. Set file and directory permissions to allow group access. Use the umask command to control the default protection of files you create. You may also wish to try symbolic links ("ln -s" command) to permit easy access to the common files from your own directory. If the class groups (e.g., "cs384t21") are set up in time, use your specific group for the common files; otherwise, use the "student" group for now.

Lab report (due 11:00pm, the day prior to week 2 lab)

Your report should include:

  • A discussion of how you approached the problem. This should contain a sufficient level of detail to convince your instructor that you were thinking as you worked on this assignment.
  • Sample program output.
  • A brief description of any problems you encountered or questions you have regarding the lab.
  • A description of how each team member contributed to the project, and an activity log indicating how much time each of you spent on the assignment (following the template provided in the lab1.xml template document). Please use the following categories:
    • Design
    • Coding
    • Debug (before you think it's working)
    • Test (after you think it's working)
    • Documentation
    • Other
  • Any suggestions you have for how the lab could be improved.
  • Documented source code
    You may wish to use gensrc, a shell script which will produce an XML document that may be used as a starting point for your report. The file will include all of the source code files (provided you modify the script appropriately... edit gensrc for details on how to do this.)

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic submission guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well.

Your grade will depend on quality of design, clarity of code and documentation, as well as whether your program produces the correct results. If you have any questions, consult your instructor.

© 2002 Dr. Christopher C. Taylor Office: CC-27C Phone: 277-7339 Last Updated: Tue Dec 3 17:21:48 2002
I am responsible for all content posted on these pages; MSOE is welcome to share these opinions but may not want to.