Skip to content

Resolution proposal of the first project of the Operating Systems course unit

License

Notifications You must be signed in to change notification settings

ctrlMarcio/feup-sope-proj1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

feup-sope-proj1

C/C++ CI Build C/C++ CI Documentation GCC version bash version

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.

Files

Source files

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.

Compiling

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.

Usage and running

The usage of the program is similar to the du usage, with some tweaks.

simpledu [OPTIONS]

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

Exit codes

  • 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.

Log file

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

Features

Feature Status Additional info
Argument reading and processing https://img.shields.io/badge/great-%20-brightgreen N/a
Different exit code for each error https://img.shields.io/badge/great-%20-brightgreen N/a
Dereference links https://img.shields.io/badge/good-%20-yellowgreen Not working if a loop occurs
Specify the max depth of the search https://img.shields.io/badge/great-%20-brightgreen N/a
Directory and file size communication with pipes https://img.shields.io/badge/great-%20-brightgreen N/a
Directory handling with different a processes https://img.shields.io/badge/great-%20-brightgreen N/a
Show all files and directories (option -a) https://img.shields.io/badge/great-%20-brightgreen N/a
Signal handling https://img.shields.io/badge/good-%20-yellowgreen N/a
Log information https://img.shields.io/badge/great-%20-brightgreen N/a
Different size according to block size or bytes https://img.shields.io/badge/great-%20-brightgreen N/a

Authors

License

MIT

Disclaimer

This repository contains the solution proposed by the authors and might contain errors as well as lack of efficiency.

About

Resolution proposal of the first project of the Operating Systems course unit

Resources

License

Stars

Watchers

Forks

Packages

No packages published