CPSC 457 - Principles of Operating Systems - Assignment 1

This assignment comes in two parts. Part A is a programming assignment to familiarize you with coding in C and with using the Linux System Call Libraries. It can be completed on any Linux machine, but must run on the machines in our undergrad lab.

Part B includes questions to be answered which will encourage you to think about some of the work you did in Part A and will expose you to the style of question you can expect on the midterm.

This assignment will be marked out of 50 and will count for 10% of your total grade in the course. 30 marks will be dedicated to Part A and 20 marks will be dedicated to Part B (four marks for each question).

You will hand in your assignment by sharing your git repository with your TA through the CPSC gitlab and Tagging the, branch which includes all of your files for Part A and Part B, "CPSC457-Assignment1-Complete".

This assignment is due at 2:00pm on Friday May 20.

Part A - Coding

Graphical ls is a program that you will write. It will allow you to see a tree of the files (and directories) in a directory as well as some basic information about those files.

Graphical ls

This assignment is to familiarize yourself with C and with the mechanism for using system calls in Linux (via C).

ls is a utility that allows you to list files in the file structure of *nix systems and allows you to see various information about those files. Your assignment is to use the system calls in Linux to access this information programmatically.

For this assignment, you will write a utility called gls that shows a tree of all of the files in a directory, and recursively, all of the files in each directory it contains. Compare the output of ls -lR to the gls sample output below.

Sample Output

Script started on Fri May 7 14:04:35 2004 Erase is control-H Kill is control-] [praxxis]teaching/457/dir_asgt : ls -lR total 112 drwxr-xr-x 3 cliff bin 137 May 7 14:04 ./ drwxr-xr-x 15 cliff bin 4096 Dec 8 08:54 ../ -rw-r--r-- 1 cliff bin 0 Jun 12 2003 A -rw-r--r-- 1 cliff bin 0 Jun 12 2003 B drwxr-xr-x 4 cliff bin 49 May 6 15:16 C/ -rw-r--r-- 1 cliff bin 59 May 4 10:18 NOTES -rw-r--r-- 1 cliff bin 5266 May 7 13:53 SRC.ar -rwxr-xr-x 1 cliff bin 25532 May 7 13:52 gls* -rw------- 1 cliff bin 4103 May 7 13:52 tree.c -r--r--r-- 1 cliff bin 3065 May 7 12:37 tree.c.orig -rw-r--r-- 1 cliff bin 0 May 7 14:04 typical_run ./C: total 0 drwxr-xr-x 4 cliff bin 49 May 6 15:16 ./ drwxr-xr-x 3 cliff bin 137 May 7 14:04 ../ -rw-r--r-- 1 cliff bin 0 Jun 12 2003 D -rw-r--r-- 1 cliff bin 0 Jun 12 2003 E drwxr-xr-x 2 cliff bin 19 Sep 17 2003 F/ drwxr-xr-x 2 cliff bin 134 May 7 12:52 G/ ./C/F: total 0 drwxr-xr-x 2 cliff bin 19 Sep 17 2003 ./ drwxr-xr-x 4 cliff bin 49 May 6 15:16 ../ lrwxr-xr-x 1 cliff bin 4 Sep 17 2003 H -> ../D ./C/G: total 0 drwxr-xr-x 2 cliff bin 134 May 7 12:52 ./ drwxr-xr-x 4 cliff bin 49 May 6 15:16 ../ -rw-r--r-- 1 cliff bin 0 Jun 18 2003 H -rw-r--r-- 1 cliff bin 0 Jun 18 2003 I -rw-r--r-- 1 cliff bin 0 Jun 18 2003 J brw-r--r-- 1 root root 0, 97 May 7 13:28 blk_dev crw-r--r-- 1 root root 2, 21 May 7 13:28 chr_dev lrwxr-xr-x 1 cliff bin 14 May 7 12:52 my_printer -> system_printer* prw-r--r-- 1 cliff bin 0 May 6 15:12 printer_port| lrwxr-xr-x 1 cliff bin 12 May 6 15:17 system_printer -> /dev/printer* [praxxis]teaching/457/dir_asgt : ./gls usage: './gls <directory_name>' [praxxis]teaching/457/dir_asgt : ./gls . | A (regular file - 302 - 87086e42b2fb69077955ecc75cf01f6b) | B (regular file - 42239 - 3cac0309369dd4fccf0b1ac23b091c9a) | C (directory - 16770) | D (regular file - 8192 - b2c930a89fc6b5d8334e9ba4af75428c) | E (regular file - 0 - a3d01d479bf1906e8bdc6d0d6f196ef5) ---| F (directory - 0) | H (symbolic link - points to '../D', absolute path : '/home/cliff/teaching/457/dir_asgt/C/D') ---| G (directory - 8578) | H (regular file - 8221 - d9c2dbfb8e588b41f7b2a77800115d62) | I (regular file - 57 - 6150fe5c4271c87e90a6bd105363c39a) | J (regular file - 300 - d9cd94e7f7ea05530c0c92166dc96484) | printer_port (fifo (named pipe)) | chr_dev (character special device) | my_printer (symbolic link - points to 'system_printer', absolute path : '/dev/printer') | blk_dev (block special device) | system_printer (symbolic link - points to '/dev/printer', absolute path : '/dev/printer') | gls (regular file - 2125 - f016e215ece68365d2d4d1f6fd22d1fe) | SRC.ar (regular file - 17232 - 390bf6593cdb990acc9facdb3377c3a6) | gls.c (regular file - 3982 - 11fbf99649d98436c5589d6afee63c56) | typical_run (regular file - 32981 - e51e4699504ad688be0a19bd539a8e75) | gls.c.orig (regular file - 4218 - 192de841a1eed04093658b47928bea13) | NOTES (regular file - 1332 - 6978ff49cb9ae5c077542816f38a14b3) [praxxis]teaching/457/dir_asgt : script done on Fri May 7 14:04:50 2004

Functional Requirements

Your assignment must:

  • Print the contents of a directory and any directories it contains as a tree.
  • For each file, include:
    • the file type.
    • if the file is a symbolic link, the path to which the link resolves
    • if the file is a regular file, an md5 checksum of the file and the size of the file.
    • if the file is a directory, the sum of the size of all files and directories contained in the directory (to an arbitrary depth).

Non-Functional Requirements

Your assignment must:

  • Be written in C.
  • Use library calls to access the file information.
  • Use a library to calculate MD5 checksums, do not implement the algorithm yourself!
  • Be well-commented.
  • Must cite all out-of-class resources.
  • Include a usage statement
  • Include a makefile which compiles your assignment.
  • Include a README explaining the assumptions you've made, how to compile and run your program and any other notes we should know.
  • Be your personal, original work.

Part B

Part B includes five questions, which should be answered in one or two paragraphs and included in a text file along with your code, makefile and README when you hand in your assignment. Most questions have several parts, make sure you answer them all.

Question 1 - Linux and C

Why is Linux written in C? Would it be better to write an operating system in a higher-level language? Would it be better to write an operating system in a lower-level language?

Question 2 - Linux History

Who is the originator of Linux? What date was Linux first announced to the world? What was the original purpose of Linux? When was the Linux Foundation founded? What is the purpose of the Linux Foundation?

Question 3 - stat

What is the difference between st_size and st_blocks? Should you be able to calculate one from the other? What are the differences between each of the three timespec fields? What Linux command lets a user change the access and modification times of a file?

Question 4 - Privileged Instructions

Instructions related to accessing I/O devices are typically privileged instructions, that is, they can be executed in kernel mode, but not user mode. Give a reason why these instructions are privileged. (From Modern Operating Systems, Chapter 1)

Question 5 - Libraries

To a programmer, a system call looks like any other call to a library procedure. Is it important that a programmer know which library procedures result in system calls? Under what circumstances and why? (From Modern Operating Systems, Chapter 1)

Page Updated: May 11, 2016 at 840 MDT