ISP: Assignment 1

The assignment is due Monday, September 27, beginning of class.

See coding guidelines for suggestions on C style.

You may develop your programs on any system (cunix, home, office, ...) However, your programs must compile and run on the CLIC Solaris or Linux machines, preferably both. In your solutions, indicate which operating system you used.

Submitting Your Work

Please use the "submit" script to submit files for the programming portions of the assignment according to the instructions below:

You will receive email to confirm your submission was received.

On-campus students should turn in the hardcopy of their writeups for the assignment before class on the due date. Off-campus (CVN) students should use the normal CVN channels (fax, overnight mail, ...) to submit their homework on the due date.


  1. CVS: Import a "hello world" program into the CVS repository at, using cvs import. Use your login name, without the host part, as your module name.

    The script to add setup your userid and module in the CVS repository is available from the CLIC and CS systems. You should invoke this script by entering

    /proj/class/isp/add_cvs_user  your_userid

    Once this script completes, you can login to the CVS repository and complete the exercise using the following guidelines:

    CVS repository:
    CVS server hostname:
    CVS rdir (for import):

    your_userid (for the add_cvs_user, CVS login, and import is your CLIC/CS username.

    Login using

      cvs -d login

    Document the steps you took; we will be able to see your sample files.

    In addition to importing your code, take the proper steps (described in the CVS documentation) to protect files in your modules from anyone who is not logged into CVS with your userid. We will check your work for exercise 1 through your writeup and through your setup in CVS. However, we will not use files in the CVS repository to grade your programming exercises. You must use the steps described above to turn in your files and writeup.

  2. purify: The C program insort.bad.c simply adds words to a list and then destroys the list. It runs, but it has a number of common problems that may cause it to fail on some systems. Use purify to find the problems (even though you can probably see them by inspection...). Also, try ElectricFence. Does it catch the same bugs? CVN students only: If you do not have access to purify, you may use ElectricFence only.

    The default purify only works on Solaris 2.6, /import/pkg/pure-4.5b/purify-4.5-beta-L4-solaris2/purify for Solaris 2.7

    In your assignment, describe the output of purify (e.g., via a screen dump) and indicate the errors you found in the sample program.

  3. gdb: Use gdb to debug the program. In your solution, show the gdb command(s) you would use to (a) stop execution when the tenth entry is being added to the list; (b) show the element counter variable whenever it changes.

  4. truss: Write a program that uses scanf() to read a text file from stdin one word at a time into dynamically allocated memory buffer, using malloc() and realloc(). When reaching the end of file, this buffer should contain the content of the whole file.

    If you allocate memory, the malloc routines do not allocate chunks of arbitrary size (say, 17 or 23 bytes). Rather, they create chunks of some multiple number of bytes, to reduce fragmentation. The details depend on the particulars of the malloc library. Also, the sbrk or brk functions will be executed periodically to change the data memory boundary (see the man pages for these functions). Again, they generally aren't called for each call to malloc, but rather with larger increments.

    Use truss to find out (a) how often the lower-layer read() function is called; (b) what increments are used to allocate memory.

    Provide the source code, show the output of truss and your measurement results.

  5. prof: Write a sorting routine with a similar interface to qsort or find it in the FreeBSD or Linux source distributions. Use the program to write a simple program, similar to sort, that sorts lines of text alphabetically. Lines can be of any length and should be read from stdin and written to stdout; none of the other sorting features of the regular sort program need to be provided. Using the profiler, find out where the program spends most of its time.

    Provide the source code and the output of gprof and interpret the results.

Last updated by Henning Schulzrinne