Exercises:Proc: Difference between revisions

From COMP15212 Wiki
gravatar Yuron [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
pc>Yuron
No edit summary
Line 1: Line 1:
{{DISPLAYTITLE:Unix proc Exercise}}<!--
{{DISPLAYTITLE:Unix proc Exercise}}<!--
-->{{Path|Exercises|12}}<!--
-->{{Path|Exercises|12}}<!--
-->{{#set: Priority=3 | Summary=An exploration of some of the Unix internal data <i>made human readable</i> and <i>pretending</i> to be files.}}
-->{{#set: Priority=3 | Summary=An exploration of some of the Unix internal data <i>made human readable</i> and <i>pretending</i> to be files.}}<!--
-->{{#invoke:Dependencies|add|Everything is a File,4}}
The purpose of this exercise is:
The purpose of this exercise is:


Line 7: Line 8:


----
----
Unlike most of these short exercises there is no template for this,
Unlike most of these short exercises there is no template for this, other than a Unix machine upon which to run.  (However it is
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.)
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
There is a Unix directory [http://www.tldp.org/LDP/sag/html/proc-fs.html <code>/proc/</code>] which contains “files” which describe the configuation and behaviour of the system.  These are <em>virtual</em> files: they are a means of representing information in a [[Everything_is_a_File|standard form]] – they are not bytes on a disk somewhere; some values in some “files” may be different each time they are read.
[http://www.tldp.org/LDP/sag/html/proc-fs.html <code>/proc/</code>] which
contains “files” which describe the configuation and
behaviour of the system.  These are <em>virtual</em> files: they are a means
of representing information in a [[Everything_is_a_File|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
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.
directory.  This will also revisit some of the resources you have met
in other parts of the module.  As you proceed, record your findings
and thoughts in ~/COMP25111/ex12/ex12.txt, which will become your
submission.


Run
Run
Line 31: Line 20:
ls
ls
</syntaxhighlight>
</syntaxhighlight>
You’ll see some directories with names which are just a sequence of digits.
You’ll see some directories with names which are just a sequence of digits. <strong>What do you think these each represent?</strong>  Try looking inside some samples.
<strong>What do you think these each represent?</strong>  Try looking inside some samples.


Run
Run
Line 74: Line 62:
(Note the use of a [[Pipes|pipe]] in this command.)
(Note the use of a [[Pipes|pipe]] in this command.)


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


Run it again: or, for added fun, try:
Run it again: or, for added fun, try:
Line 95: Line 80:


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


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


Here are a few suggestions:
Here are a few suggestions:
Line 113: Line 95:
Explore!
Explore!
----
----
=== Submission ===
Submit your file of findings: ~/COMP25111/ex12/ex12.txt
----
{{PageGraph}}
{{PageGraph}}
{{Category|Exercises}}
{{Category|Exercises}}

Revision as of 08:28, 9 August 2019

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!