Lab #3 CIS343 Ð Observing OS Behavior

Getting Started

The files in this lab are:

 

makefile                // The makefile to compile programs

processStates.cc        // The file that demos process stuff

 

1. create a lab3 directory in your cis343 directory

2. copy all of the files from ~hardnett/pub/cis343/lab3 to your lab3 directory

3. Start reading and performing the actions of this lab. Ask questions if you do not understand something.

 

There is a Unix command that can be found on most systems. The name is

"prstat". This command shows processes in the system along with some

vital information about each processs. This also automatically updates

the information at regular intervals. You can literally watch the

system run, and watch processes move through states.

 

When you run top you will see something like this:

 

1. PID USERNAME  SIZE   RSS STATE  PRI NICE  TIME  CPU PROCESS/NLWP      

2. 10294 hardnett 1584K 1392K cpu0  58    0   0:00.00 0.6% prstat/1

3. 354 root     2552K 2160K sleep   58    0   0:00.00 0.1% mibiisa/12

4. 144 root     2992K 1440K sleep   10    0   0:00.00 0.0% keyserv/4

5. 234 root     3464K 3016K sleep   55    0   0:00.00 0.0% nscd/8

6.  58 root     2240K 1896K sleep   51    0   0:00.00 0.0% picld/8

7. 141 root     2392K 1496K sleep   58    0   0:00.04 0.0% rpcbind/1

 

line "1." has heading for the information about each process, and for

now we are only looking at the following:

PID - Process ID

USERNAME - owner of the process

SIZE - memory needed program/data/stack

RES - amount of physical memory allocated

STATE Ð process state

PRI Ð Priority (higher numbers => higher priority)

NICE Ð nice value for priority computation

TIME Ð cumlative time of the execution

CPU - raw percentage of the CPU

PROCESS/NLWP Ð the Process and the number of threads

 

open 2 shelltools, and make them small enough so that they can all fit

on the screen together.

 

In the first shelltool:

 

% prstat -u hardnett -n 10 0

 

In the second shelltool:

 

change to your lab3 directory, and type the following:

 

% more processStates.cc

 

Note that this program just loops and sleeps. This will allow you to see changes in the states.

 

% make processStates

 

Now try running two programs in the background like this:

 

% processStates &

 

% !!

 

Examine the CPU percentages for these 2 processes.

 

Q1.  Try running 3, 4, 5, and more of these processStates programs in the background. Examine the CPU percentage, and describe what you see happening as the number of processes increase.

 

Examining Process Descriptors via Core Files

Everyone is familiar with core dumps which typically result from segmentation faults. What is a core dump? Core is an old name for primary memory, and the core dump is the state of memory for a given process at a particular point in time. In the case of a segmentation fault, the core dump is the state of memory at the point of the fault. We can also view the core dump as the state of the process descriptor at a given point in time.

 

In some systems like Solaris, there is a command that allows you to dump core for a given process id. This program is called gcore.

 

To use it, you need a process id. So in your shelltool window type:

 

% ps

 

PID   TTY      TIME CMD

23903 pts/6    0:00 csh

 

 

We will examine the csh process. Write down the pid of your csh process, you will need it for the various commands. In the example, the pid of csh is 23903.

 

First we need a core file. Use gcore and your pid like below:

 

% gcore 23903

 

This will give you a file named core.<pid> in your directory. In this case the file is named core.23903.

 

Now you can analyze the process using a series of commands: proc, pflags, pcred, pmap, pldd, psig, pstack, pfiles, pwdx, pstop, prun, pwait, ptree, ptime

 

All of these commands take the core file or pid as the argument to work on:

 

pmap <options> <core_file>

 

ptree <options> <pid>

 

Run ptree on your pid:

 

% ptree 23903

 

and run pmap on your core file:

 

% pmap core.23903

 

Using the man page for all of these commands answer the following questions. The man page is:

 

% man proc

 

Q2. Which command allows you to see the call stack of the process?

 

Q3. Which command and option allows you to see the current status of the registers?

 

Q4. Which command allows you to see the address space?

 

Q5. What dynamic libraries are being used by your process?

 

Lab Sessions

This lab will take place during 1 session: Monday (2/9)

Deliverables

Create a file called lab3.ans in your lab directory, and put the answers to questions Q1-Q5.

Submission

You need to submit this assignment by 8AM February 10th (the next day).

 

% cd ~cis343/lab3

 

% turnin cis343 lab3

 

NOTE: view the output of the turnin to verify that all of the necessary files have been submitted.