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
Suggestions:
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
create a directory, sibling of the work directory and named bin
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:
Suggestions:
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
).