edit · history · print

Observing Linux Behavior

Objective

This exercise is to study some aspects of the organization and behavior of a Linux system by observing values stored in kernel variables. You will write a program to use the "/Proc" mechanism to inspect various kernel variables that reflect the machine's load average, process resource utilization, and so on. After you have observed the kernel status, you will prepare a report of the cumulative behavior that you observed.

Background

The /Proc file system, according to McKusick, et al [1998], comes from UNIX Eight Edition and has been used with 4.4 BSD. "In the /proc system, the address space of another process can accessed with "read" and "write" system calls, which allows a debugger to access a process being debugged with much greater efficiency. The page (or pages) of interest in the child process is mapped into the kernel space. The requested data can then be copied directly from the kernel to the parent address space." In addition, /proc can be used to collect information about processes in the system, even though that is not done in 4.4 BSD. [1]

The /proc file system is an OS mechanism whose interface appears as a directory in the conventional UNIX file system (in the root directory). You can change to /proc just as you change to any other directory. For example ,

% cd /proc

makes /proc the current directory. A file in /proc or one of its subdirectories is actually a program that reads kernel variables and reports them as ASII strings. Some of these routines read the kernel tables only when the pseudo file is open, whereas others read the tables each time that the file is read. Files in /proc are read just like ordinary ASCII files. For example, when you type to the shell a command such as

% cat /proc/version

You will get a message printed to stdout that resemble the following:

% Linux version 2.4.20-20.9 (bhcompile@stripples.devel.redhat.com) (gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #1 Mon Aug 18 11:45:58 EDT 2003

To read a /proc pseudo file's contents, you open the file and then use stdio library routines such as fgets() or fscanf() to read the file. The exact files read depends on the specific Linux version that you are using. To find out exactly which file interfaces are available to you through /proc, read the /proc man page on the system.

Other materials are

  1. LKP Appendix C: The Proc File System, pp 406-422
  2. The Linux Kernel Module Programming Guide, Chapter 5

[1] Kernel Projects for Linux, Gary Nutt, Addison Wesley 2001

Problem Statement

Write a program to report the behavior of the Linux kernel by inspecting kernel status. The program should print the following values on stdout:

  • CPU type and model
  • kernel version
  • amount of time since the system was last booted, in the form dd:hh:mm:ss
  • the number of processes that have been created since the system was booted
  • a list of load averages (each averaged over the last minute for 10 minutes)
  • report date (gettimeofday) and machine hostname

How and what to hand in

Create a subdirectory named lab2.* under your Uml directory on elgate. Put your source code, executable, and a readme file under this directory.

edit · history · print
Page last modified on August 30, 2006, at 08:51 PM EST