User Tools

Site Tools

Return to Home page

Return to Operationg Systems home

Operating Systems Course: Lab02

Laboratory number 02

Exercise 01: Recursive visualization of a directory

Write a program in C language able to:

  • receive on the command line the path (absolute or relative) of a directory tree
  • display recursively the contents of this tree (i.e., all files, sub-directories, files in sub-directories, etc.).

Compile the program with gcc and verify its operation comparing the results with the shell command ls -R


  • Write a recursive procedure that generalizes the non-recursive display of a directory analyzed in the class lesson
  • Pay attention to the managing of the paths of the directories/files
  • Explicitly manage the directories “.” and “..” to avoid endless recursions.

Exercise 02: Compilation and makefile

  • Compile the program of the previous exercise using a Makefile containing only the compilation target.
  • Edit the previous Makefile by adding the install target, which allows to
    1. create a directory, sibling of the work directory and named bin
    2. move the created executable in this directory
  • Edit the previous Makefile by adding the clean target, which removes the object file in the current directory
  • Edit the previous Makefile by adding the distclean target that calls the clean target and deletes the bin directory (which is the sibling of the current directory) and all its content
  • Edit the previous Makefile using variables to specify the compiler, the compilation options, and the file name.

Take as reference the example analyzed in classroom: Makefile4

Exercise 03: Recursive copy of a directory

Write a program in C language able to:

  • receive on the command line two paths (absolute or relative)
  • copy recursively the content of the directory identified by the first path in an identical directory with root the second path.


Modify the recursive visit procedure of a directory tree created in Exercise 01. During the visit of the source directory, create an identical copy of each “entry”

  • re-creating the directories (using the system call mkdir) in the destination directory
  • re-copying the files (using system call open, read, write and close).

If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at]

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url:
/web/htdocs/ · Last modified: 2020/11/26 23:18 (external edit)

Privacy Policy