Background:

The Linux /proc file system is a "pseudo" file system that exists only in kernel memory and is used primarily for querying various kernel and per-process statistics. Although the /proc file system is virtual, you can open and read the virtual files the same way as any other file. So you can start this assignment without the instructor discussing the /proc file system.

You will answer questions about turing by writing a program that reads some virtual files in the /proc/sys/kernel/ directory, and the four virtual files: /proc/cpuinfo, /proc/uptime, /proc/stat, and /proc/swaps.

a) Review the C++ string class and use it in this program. Use member functions of the string class to process strings. For example, to search for a substring in a string, you can use the string member function find().

b) In /proc/cpuinfo, the majority of the input fields repeat for each processor. Processor numbers need not be contiguous, so you need to count the number of processors. Each processor block in the /proc/cpuinfo corresponds to a CPU core. A physical chip can have multiple cores. A host such as turing.cs or hopper.cs can have several physical multi-core chips.

c) To get the number of physical multi-core chips, you must keep track of the number of "physical id"s.

d) Look at the "cpu cores" field to get the number of cores for each physical multi-core chip.

e) You may only read each file once and you do not know which order the keywords will come in, so you need to read the file, save the fields you need, and then format your output.

f) The file /proc/stat records information about the system since it was started, including:

  • cpu
    • Total CPU time (unit is architecture dependent. 1/100ths of a second for this assignment) spent in user mode, low-priority user mode (nice mode), system mode, idle, and others.
  • cpuN
    • Times for CPU N.

g) /proc/uptime provides two numbers. Use the manual page for proc to find out what they are.

h) The file /proc/swaps provides information on swap devices. The units of size and usage are kilobytes.

i) Command "man proc" is the manual page and can give you more details of the /proc file system.

Program Output

You need to express each output in a numbered complete sentence, e.g.:

A: Questions about turing’s OS:
1. The type of turing’s OS is __ .
...

B: Questions about turing’s processor:
1. Turing has __ processors.
2. Turing has __ physical multi-core chips. (if there is only one: 1 physical
multi-core chip.)
...

You can decide the exact sentence as long as you format the answers in a human readable way.

Your program output is expected to answer the following questions:

A. Questions about turing’s OS. Read the following files under the directory /proc/sys/kernel/
and format the output in a readable way.
1. ostype
2. hostname
3. osrelease
4. version

B: Questions about turing’s processors:
1. How many processors (CPU cores) does turing have?
2. How many physical multi-core chips does turing have?
3. How long has turing been up in seconds?
4. Express that time in days, hours, minutes and seconds
(e.g., 7 days, 1 hour, 2 minutes, and 4.3 seconds)

C. For processor 0, answer these questions:
1. Who is the vendor?
2. What is the model name?
3. What is its physical address size?
4. What is its virtual address size?

D. For processor 1, answer these questions:
1. How long has it spent time in user mode in seconds (not including low-priority user mode)?
2. How long has it spent time in system mode in seconds?
3. How long has it been idle in seconds?
4. How long has it been idle in days, hours, minutes and seconds?

E. What is the size of turing’s swap device in MB?
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.