Unix proc Exercise

From COMP15212 Wiki
Revision as of 10:22, 9 August 2019 by gravatar W81054ch [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
On path: Exercises 0: Exercises • 1: Pointer Exercise • 2: Arguments Exercise • 3: Malloc Exercise • 4: Structs Exercise • 5: Processes Exercise • 6: Shared memory Exercise • 7: Pipes Exercise • 8: Exceptions Exercise • 9: Synchronisation Exercise • 10: Files Exercise • 11: Threads Exercise • 12: Unix proc Exercise
Depends on Everything is a File

The purpose of this exercise is:

  • to explore a real system and rediscover some of the concepts previously encountered.

Unlike most of these short exercises there is no template for this, other than a Unix machine upon which to run. (However it is recommended that you try your experiments on more than one machine: perhaps a desktop machine and by a remote log-in to a server.)

There is a Unix directory /proc/ which contains “files” which describe the configuation and behaviour of the system. These are virtual files: they are a means of representing information in a standard form – they are not bytes on a disk somewhere; some values in some “files” may be different each time they are read.

This exercise explores some of the information available in this directory. This will also revisit some of the resources you have met in other parts of the module. As you proceed, try to record your thoughts in your favourite note-taking software - even a plain text file is fine. It'll help you learn.

Run

cd /proc
ls

You’ll see some directories with names which are just a sequence of digits. What do you think these each represent? Try looking inside some samples.

Run

echo $$

what is that?

Run (note no / on the end)

ls -l $$/cwd

and explain.

Run (note no / on the end)

ls -l self

and explain.

Run

ls -l self/

and explain.

Run

ls -l self/root

and then

man chroot

Exploration

Try this one:

cat /proc/cpuinfo |grep MHz

(Note the use of a pipe in this command.)

This extracts the clock frequencies (averaged over some time interval) of the various processor cores. A typical desktop machine may have maybe four processor cores. A server will often have more: kilburn (for example) has 12.

Run it again: or, for added fun, try:

watch -n 1 'cat /proc/cpuinfo |grep MHz'

depending on your machine the values may change. If so this will be due to power management software adjusting the speed to accommodate processing demands or avoid overheating.

An alternative, available on some systems, might be watch -n 1 'cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq' (this exact specific does not work on kilburn, for example but you may be able to discover some alternative which does.) /sys/ is another synthetic file system in Linux; somewhat older than /proc/.

Your turn

Find (at least) five more ‘non-digit’ things in /proc and explain what you think they may be; try to relate these to concepts you have seen previously in this module. Don’t be lazy! pick examples scattered around. For each item, identify the source and write a few words (not more than one sentence) on what you think it might be telling you.

You do not have to be exactly (or even slightly!) correct – the value is in the looking, not the Googling – but if you can get the right definition, Well Done You.

Here are a few suggestions:

  • acpi/processor/*.
  • Have a look at the information given by meminfo: which of the categories and keywords can you identify? (You should be able to get quite a few, now, but probably not the majority!) With a few tries you may see values changing. (This works better if you look at a server, where there are more likely to be active processes. Alternatively, run some other jobs whilst you are watching.)
  • cpuinfo – plenty more to look at, there.
  • devices – that’s a bit more cryptic
  • interrupts
  • ioports

Explore!