CS 3733 Operating Systems, Fall 1996 Assignment 2


This assignment concerns the proc file system. In this assignment you will learn about a number of data types related to processes.

Do this assignment only on the Solaris 2.5 machines. All of the Sparc 4's and Sparc 5's are running Solaris 2.5. The server, pandora, is also running Solaris 2.5.

Read Exercise 3.12 which starts on page 130 of PUP.
To find out about the proc file system under Solaris 2.5, do a man -s4 proc.

Write the function get_prstatus described on page 133. Put this in a file called procutil.c.

Write a similar function get_pspinfo(int pid, prpsinfo_t *psp) which does a PIOCPSINFO ioctl to fill the structure pointed to by psp.

Write the function output_prstatus described on page 133. Write a similar function output_psinfo.

Each of these will only output a small subset of the available information, but each piece of information should be in a form that is nicely formatted and easily understood, that is, in plain English. Output the fields exactly in the order given below.

The fields that must be handled by output_prstatus are

The fields that must be handled by output_psinfo are

Write a main program which takes two command line arguments, a process ID, and a file name. All output from the main program should go to either standard output or the given file. The main program will do the following:

  1. Print a line to standard output in the form:
    This program was written by (your full name)
  2. Check that the command line arguments are appropriate and exit with an informative message if not.
  3. Create a file with the given name for writing. If the file already exists, open the for writing and truncate it to zero length. If an error occurs print out an informative message and exit.
  4. Output a line to the file in the form
    Process information generated by (your full name)
  5. Do the following in a loop 10 times:
    1. Output the following line to the opened file:
      prstatus information follows:
    2. Call get_prstatus for the given process ID followed by output_prstatus with output going to the opened file.
    3. Output the following line to the opened file:
      psinfo information follows:
    4. Call get_psinfo for the given process ID followed by output_psinfo with output going to the opened file.
    5. Output a blank line to the opened file.
    6. Sleep 1 second.
  6. Output the following line to the file:
    Processing Done
  7. Close the file.

Test your program by running my program:
/usr/local/courses/cs3733/pup/proctest/proctest1 abc def gh
This program will run for a long time or until you hit Ctrl-C. It will start by printing out its process ID. After starting testproc1 running, test your program using the process ID of proctest1. Only exit proctest1 after your program has finished.

The following should be handed in in one packet staped together in the order given. All pages should be numbered with the cover page page 1.

  1. The filled in cover page available in /usr/local/courses/cs3733/fall96/cover2.ps
  2. Source code for your main program.
  3. Source code for your functions in procutil.c
  4. Lint output for all of your programs.
  5. A printout of the file generated by your program for proctest1.