CS-384 Lab 1: UNIX System Calls
Dr. Mark J. Sebern
Overview
The purpose of this lab is to review the C++ programming environment on the UNIX
operating system and to make use of some simple operating system calls.
Prerequisite check
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.
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@torres.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 "Tuesday,
December 1, 1998, 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. You may wish to use the <strstream>
library for formatting the ID values, since the currently available version of g++
does not provide the "string stream" library.
- 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 teams 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.
Report
Prepare a text file containing a brief report (one report per group)
detailing any problems you encountered and any questions that remain about the lab
material. Create a compressed tar archive file (e.g., "lab1_21.tar.Z", where "21"
is your team number) containing the report, source, and make files (no object or
executable files) from this lab. Attach this file to a mail message, and send it to sebern@msoe.edu. Do not discard your original files, in
case anything gets lost in the email system.
In the report, identify the members of your lab group, by name and
username. The report is due two hours before the start of the following lab.
This page was last updated on November 29, 1998; send comments to Mark Sebern.