- Short Description: Tool to estimate file space usage
- Environment: Unix
- Tools used: C
- Institution: FEUP
- Course: MIEIC
- Curricular Unit: SOPE (Operating Systems)
- Diogo Samuel Fernandes (up201806250@fe.up.pt)
- Hugo Guimarães (up201806490@fe.up.pt)
- Telmo Baptista (up201806554@fe.up.pt)
make
make clean
The executable file is in ./bin/
directory after you run the command make
in terminal.
Note that the flag -l
or --count-links
must be present.
./bin/simpledu -l [path] [-a] [-b] [-B size] [-L] [-S] [--max-depth=N]
or can be run via the symbolic link created by make
./simpledu -l [path] [-a] [-b] [-B size] [-L] [-S] [--max-depth=N]
The aim of the project was to develop a tool to summarize the use of disk space in a file or directory, the information to be made available must include files and subdirectories that may be contained therein.
This tool has as reference the command du
, which presents information about the disk space used by files and directories.
-a
or--all
- the displayed information also concerns files-b
or--bytes
- displays the actual number of data bytes (files) or allocated (directories)-B
,--block-size=SIZE
- defines the size (bytes) of the block for representation purposes-l
,--count-links
- count the same file multiple times;-L
,--dereference
- follow symbolic links;-S
,--separate-dirs
- the displayed information does not include the size of the subdirectories;--max-depth=N
- limits the displayed information to N (0.1, ...) levels of directory depth
Every functionality mentioned bellow is full working.
- Receive, process and save command line arguments and environment variables
- Add registration messages as new features are implemented and validate the correction of both
- Start by choosing only files and presenting the desired information (bytes and blocks)
- Consider that the
-L
(or--dereference
) option is active so that it is not necessary to distinguish symbolic links from regular files
- Consider that the
- Distinguish between files and symbolic links and present different results depending on the
-L
option - Consider entries that are directories, but limit the analysis to one level (
--max-depth=1
) - Create a new process by subdirectory and try to pass the correct arguments to it
- The arguments will be the same except for the path (path / entry) and, eventually, the maximum allowed depth level (
--max depth=N-1
) - Assume that the
-S
(or--separate-dirs
) option is active so that it is not necessary to cumulatively consider the size of the subdirectories
- The arguments will be the same except for the path (path / entry) and, eventually, the maximum allowed depth level (
- Create pipes to communicate the size of a given subdirectory to the parent process and thus correctly present cumulative results, including for subdirectories
- shows the space occupied in number of blocks of 1024 bytes
- only lists directories
- does not follow symbolic links
- counts each file only once
- cumulatively displays the size of included subdirectories and files
- does not restrict the depth levels in the directory structure
- Each process
- analyses only one directory
- create a process for each subdirectory
- adjust arguments passed to child processes
- The parent process (first to be executed) must always wait for the termination of all child processes before finishing its execution
- use the same code (without changes) regardless of being the main process or not
- the total size of each of the subdirectories must be communicated to the parent process through a pipe (without a name) created for each of the child processes
- the parent process must send a
SIGSTOP
signal to all child processes that are running when it receives a SIGINT signal
The sending of the next signal depends on the confirmation (SIGTERM
) or not (SIGCONT
) by the user regarding the termination of the program
- Logs
- Logs functionalities
- Log creation and termination of processes
- Log sent and received signals
- Log sent and received data from pipes
- Log files and directories analysed by each process
- Output format:
instant - pid - action - info
- instant - time immediately preceding the record, measured in milliseconds and to 2 decimal places, with reference to the time when the program started executing
- pid - process identifier that registers the line, with a fixed space for 8 digits
- action - description of the type of event:
CREATE
,EXIT
,RECV_SIGNAL
,SEND_SIGNAL
,RECV_PIPE
,SEND_PIPE
andENTRY
- info - additional information for each of the actions
-
CREATE
- the command line arguments -
EXIT
– exit status -
RECV_SIGNAL
- the received signal (for example,SIGINT
) -
SEND_SIGNAL
- the signal sent followed by the pid of the process for which it is intended -
RECV_PIPE
- the message sent -
SEND_PIPE
- the message received -
ENTRY
- number of bytes (or blocks) followed by the path
-
- When user sends
SIGINT
signal (CTRL + C
):- Entire program suspended
- Upon confirmation of termination
- Finish all pending operations
- End program
- Upon confirmation of continuation
- Resume operations immediately
-
We use
gettimeofday()
to get the clock time. On our system this clock have µs precision, but this is not guaranteed. We used this function instead of usingclock()
because in our system, the first one provided us more accuracy than the second one. -
The results of command simpledu when the flag -B / --block-size is set can have some imprecisions.
- Flags passed by the command line don't require to be in that order and can also be grouped, such as:
./simpledu -laLSB 2048 path/random
- Multiple paths can also be passed to the tool, resulting the tool to display the information for the paths in the order they are passed
./simpledu -la ./src ./include
results in
4 ./src/log.c
20 ./src/main.c
8 ./src/parse.c
4 ./src/sig_handler.c
8 ./src/utils.c
44 ./src
4 ./include/log.h
4 ./include/parse.h
4 ./include/sig_handler.h
4 ./include/utils.h
16 ./include/
Note that the position of the path doesn't matter, this is equivalent to the last example:
./simpledu ./src -la ./include