Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Ho Chi Minh University of Technology

Faculty of Computer Science and Engineering

Operating Systems
Laboratory Report 1

April 24, 2021

Student’s name: Vu Hoang Hai


Student ID: 1952669
Class: CC01 - CO2017
Date Performed: March 20, 2021
Instructor: Le Thanh Van

1 Questions

1.1 What are the advantages of Makefile? Give examples.


Advantages of Makefile includes:

– Makefile enables the coding script to be more coherent and concise when compiling
and debugging for errors.
– Makefile compiles files where changes have been made instead of rerunning all the
compilation process when making changing to a class or functionality, leveraging
the tedious and lengthy command-lines.
– Makefile is widely used in order to present project in more systematic and efficient
way rather than an entangled representation of code script.
– For large software projects, using Makefile can substantially reduce build times if
only a few source files have changed
For example, in order to build and compile a C program, given that there are multiple
“.c” files. Each time there is a change in one of the files, you’d have to recompile
everything and go through the tedious process of creating “.o” and “.exe” files for all
scripts. With makefile, it is automatically done on updated files and keep the program
up to date.

1
1.2 In case of source code files located in different places, how can we write
a Makefile?
In case of source code files located in different places, for each sub-directory, there
should be a separate makefile in each directory that builds the relevant files.

If there are references to files whose build commands are in different makefiles, it
automatically associate build rules in the other makefiles. Hence, we just need to write
the superdirectory makefile and all relevant files will be loaded.

2 File commands

2.1 Create a new directory entitled with your student ID.

2.2 Create a new file hexample.txti under folder hStudentIDi with the pro-
vided content.

2
2.3 List the content of hStudentIDi directory

2.4 View the content of file hexample.txti

2.5 Show first 5 lines from hexample.txti

2.6 Show last 5 lines from hexample.txti

3
2.7 List all commands that have been run from that terminal session and
save to hStudentID/history.txti

3 Programming

Given header files named f actorial.h and readline.h have the following contents
// factorial.h

#ifndef FACTORIAL_H
#define FACTORIAL_H

int factorial (const int aNumber );

#endif

// readline.h

#ifndef READ_LINE_H
#define READ_LINE_H

int read_line(char *str);

#endif

3.1 Write f actorial.c to implement function f actorial(), the function get an


integer and return its factorial.
– Program code on Cygwin:

4
– Compilation:

5
3.2 Write readline.c to implement read line(), read line() gets data from
stdin.h (keyboard), line-by-line.
The content from stdin.h will be recorded on the parameter of this
function named str. The result of read line() indicates that whether
the line is an integer or not
– Program code on Cygwin:

6
– Compilation:

3.3 Write main.c to create an executable file named myf actorial that reads
input from stdin line by line and compute factorial if the line is an
integer (each line does not exceed 50 letters).
Then print factorial if the line is an integer else print −1. Write a
M akef ile to compile the program at least two targets: all and clean
– Program code on main.c:

7
– Makefile code:

– Compilation via Makefile:

8
– Running program:

– Cleaning by removing .o files:

You might also like