Resolution proposal of the first project of the Operating Systems course unit.
The goal is to make a C program based to do the exactly same thing as the du
command of the Unix Shell, using the Unix API for C.
The source files are located in the src/ folder. The main function is inside the main.c
file and the most important functions are inside the simpledu.c
file. Apart from those files, there are some additional files that contain some functions that are useful for the main algorithm but not directly related to the problem.
There is a make file in order to compile the program properly. Run make
in the root directory of the repository and a binary ouput file is placed inside a bin/ folder in the repository root.
The usage of the program is similar to the du
usage, with some tweaks.
simpledu [OPTIONS]
- -l, --count-links – allows the contabilization of the same file multiple times;
- -a, --all - shows also files information;
- -b, --bytes – shows the real number of bytes, instead of blocks;
- -B, --block-size=SIZE – defines the size (in bytes) of a block;
- -L, --dereference – follows symbolic links;
- -S, --separate-dirs – doesn't count the size of subdirectories;
- --max-depth=N – limits the depth of subdirectories (default: infinite).
Note: the use of -l is mandatory
- 0 - regular execution.
- 1 - args error, error in the arguments:
- not including the -l flag;
- invalid block size;
- invalid depth.
- 1 - directory error, error in the directories:
- permission denied;
- directory not existent;
- etc.
- 2 - pipe error, error creating pipes:
- limit of file descriptors reached;
- max memory allocated for pipes reached;
- etc.
- 3 - fork error, error forking processes:
- max allowed amount of threads reached;
- fork is not supported on this platform;
- etc.
The operations done while the program is running are reported in a log file. The log file is created with the name of the environment variable named LOG_FILENAME
, or the default name '../logfile.log'.
For each execution, a header is written with the following structure:
Program executed at HH:mm, DD/MM/YYYY
Each line of the log follows the following structure:
instant – pid – action – info
with:
- instant: time elapsed after the beginning of the execution;
- pid : the ID of the process that logged;
- action : description of the type of log (CREATE, EXIT, etc);
- info : additional information.
Action | Description | Info |
---|---|---|
CREATE | creation of a process | the command line args |
EXIT | termination of a process | the exit status |
RECV_SIGNAL | reception of a signal | the received signal (e.g. SIGINT) |
SEND_SIGNAL | sending of a signal | the sent signal, followed by the pid of the process that will receive it |
RECV_PIPE | reading from a pipe | the received message |
SEND_PIPE | writing on a pipe | the written message |
ENTRY | analysing of a file or directory | the number of bytes, followed by its whole path |
This repository contains the solution proposed by the authors and might contain errors as well as lack of efficiency.