Project 1
Fall 2005
Due Date: Change! Beginning of class, Friday, 9 September.
References.
- "Kernel Projects for Linux", Gary Nutt, handout.
- See the source code at
http://lxr.linux.no/source/ Look in Documentation/filesystems for info
about the proc file system.
- "Beginning Linux Programming", Stones and Matthews, WROX publishing.
This book was required in 312-210. It's like an extended man page for all
Linux system calls.
Requirements.
Note that you cannot use the popen( ) function to read the /proc system.
Complete Lab Exercise given in the handout.
Details
- You will have to do this project on your Linux machine. Solaris (which is what icsun
runs) does have a /proc file system, but it not set up in the same way as the Linux
/proc filesystem is. Since most publically available data is for the Linux
/proc filesystem, I recommend that you use Linux.
- Note that the second and third parts require command line arguments. You can use
argv and argc to read in command line arguments in C.
- Your solution must be written in C.
- You may work on either your linux box or icsun. You may turn your program
in on either the linux server or on icsun. If you turn your project in on
the linux server follow these steps:
- Copy your program into a file with your last name. If your solution
has more than one file, create a directory with your last name.
- In your account on the linux server (IP address 147.129.16.1), create
a directory with the name "Proj1" (without the double quotes). This
directory can be nested inside a "Projects" directory if you like. Note
that you must use a ssh program to telnet into the linux server; it will
not accept normal telnet sessions.
- Now copy your file (or directory using the "-r" flag) to your account
on the linux server. An example transfer might look like:
scp barr.c 147.129.16.1:Projects/Proj1/.
The "." at the end of the command directs spc to copy the file into
a file of the same name in your account on the linux server. You may
change the "." to any name that you want. Note the ":" between the server
IP address and the path to where you want to copy the file.
- You may use any I/O functions found in stdio.h You may not,
however, use the popen( ) function.
- Information about reading and writing to files in C can be found in the book
"Beginning Linux Programming" (from 312-210) or from any book on the C language.
- All output must be in a readable format. Part of your grade will be based on the
readability of your output. For example, the time output must include day of the week, date
(including year), and time (in human-readable form).
- A few system calls must be used in your solution (eg, sleep, gettimeofday,
etc.). The "Beginning Linux Programming" book has details of these calls.
- In the second command line option the handout asks you to print out the number of disk
requests made by the system. Instead give the number of hardware interrupts ("irq")
and the number of software interrupts ("softirq").
- Output must be formatted in human friendly form. For example, printing out a time in seconds
or milliseconds is not user friendly and will receive no points. As another example, you must
break out user/system/idle times on separate lines and they must be in hours:minutes:seconds format.
- For the last part of the exercise you are required to print out memory statistics and
load average statistics. For the load average, print out the value of each load average that
you obtain and print out a final average of all the load averages that you have sampled. Two
command line parameters are given to control this calculation.
For example, to execute this option, you might say
ksamp -l 2 120
This would indicate that you are to execute option D (that's what the -l means) and take load samples
(using the appropriate file in /proc) every 2 seconds. The entire load averaging program would run for
120 seconds so, since you are to average loads over a minute, you would print two load averages, one
calculated at 60 seconds and one calculated at 120 seconds. The load average printed at 60 seconds
would be an average of 30 samples taken every 2 seconds starting with time 2 and ending with time 60.
The second load average would be printed after 120 seconds and would be the average of 30 samples taken
every 2 seconds starting with time 62 and ending with time 120. In addition, you must print out all of
the actual load average samples that you take, in this example that would be 60 samples. Make your printout
easy to read.
- When your program begins, regardless of the version requested, print the current time of day
and the hostname of the machine that you're working on.
Hints:
- A copy of the C program given in the project manual is available here.
- Note that the /proc described in the Kernel Projects in Linux book is for the
Mandrake distribution of Linux using kernel 2.2.x. The machines in
Williams 309 use Suse which uses Linux kernel 2.6.x. You can find specific information about your /proc file system
by using the "man" pages in Linux. For example, you can type
man proc
to display information about /proc. You can use the page up/down keys to move through the manual entry.
Hit the 'q' key to exit the manual.
You can find more information about the /proc file system for Linux 2.6.X
by going to link given in the reference section above. There you'll find the
details of exactly what is printed out for every subdirectory.
There are a number of library functions in the time.h library that aide in manipulating time.
See the Beginning Linux Programming book starting on page 129.
Exercise 3 in the Nutt book Kernel Projects for Linux has a discussion on page 80 of
the struct's used for storing time in the Linux Kernel.
Don't forget that you have to put your computer under some stress to
get an interesting system load. The faster your computer, the more load you'll
have to use. Running graphics intensive applications while testing is one
example. Experiment with other types of loads to get some good statistics.
Administrative concerns.
- Every file in your solution must contain a comment
giving your name and the assignment number. This comment must list every function
that is defined in the file and the purpose of each.
- There must also be a separate commnent before the main function. This
comment should briefly describe the purpose of the program, describe
how it is implemented, given the major interface elements, etc.
- Finally, each function (including the main function) must have a beginning
comment that includes the following components:
- The name of the function
- The function inputs and outputs
- Changes to any global variables or kernel data structures
- System calls made from the function
- Your program must also have appropriate comments. You do not have to comment each line
of the program, but you must comment each section, feature, and functional unit of the code.
- Your program must also be appropriately formatted with tabs, spaces, etc. You will be
penalized if your code is not easy to read.
- You must demonstrate your program to me.
- You must hand in a hard copy of all code that you use in
your solution.
- You must also put a copy of all code that you use in
your solution onto the Linux server (scp to 147.129.16.1).
- You must give me a hand written (or typed) copy of your answers to
Part A. You must also tell me what programs you used to stress your computer
in order to get interesting results when you ran your solution to Part D.
- Debugging Hint: There is a systems program named strace that will trace all
of the signals and system calls that a program receives. See the man page.
Revision History
| Date |
Revision |
| 5 Sept |
Made this cool table. |