You are on page 1of 7

OPERATING SYSTEMS LAB WEEK 1 SUBMISSION

Name:- Varun Tirthani SRN:- PES1201802027 Section:- 5F

Q1) Write about 5 Basic Linux Commands along with flags/arguments supported with screenshots of
their execution on Linux System.

1) sort
This command is used to sort the results of a particular search either alphabetically or
numerically. This can be used on directories, files and file contents.
sort <flag> filename is the syntax for the command.

Flag 1:- sort -n filename returns sorted numerical order

Flag 2:- sort -r filename returns the result in reverse order

2) cat
This command is used to display the contents of the file. It also reads, modifies and
concatenate files.
cat <flag> filename is the syntax for the command.
Flag 1:- cat -E filename is used to append $ at the end of every line in the file

Flag 2:- cat -n filename is used to enumerate all lines in the file

3) ls
This command gives the list of all the contents in the working directory.
ls <flag> is the syntax for this command.

Flag 1:- ls -a lists all the hidden contents of the directory


Flag 2:- ls -l is for long description of contents with owner settings, time stamp, permissions

4) cd
This command is used to navigate between directories of the working environment..
cd <path route> is the syntax for this command.

Flag 1:- cd / changes directory to the root directory

Flag 2:- cd ~ changes directory to the home directory

Flag 3:- cd .. changes directory to parent directory

5) grep
This command is used to search for a word or string in a file.
grep <flag> element filename is the syntax for this command
Flag 1:- grep -n element filename returns matching strings with line number
Flag 2:- grep -c element filename returns number of lines in which results match string

Flag 3:- grep -v element filename returns the lines not matching the string

Q2) Write a C program to display an array in reverse using index. Create files as illustrated:-
Client.c – contains main function to collect input on array elements from the user and calls
reverse_array function
Server.c – contains reverse_array function and prints the reversed array (use a separate
function to print the reversed array)
Header.h – contains function prototypes
make.mk – contains targets and their dependencies

The following are the screenshots of Client.c, Server.c and Header.h:-

Header.h
Client.c

Server.c
The following are the steps to execute the makefile and the output of the program:-
makefile.mk

Terminal Output
Q3) Answer the following questions in brief.
1) Why do we use Makefile?
Compiling several source code files can be a very tedious and time-consuming task.
Doing the compilation work time and again because of changes in the program
implementation makes the whole process even more tiresome. Makefiles are those
files that help in building projects containing several source code files ,automatically,
and also help in their management and maintenance.
2) Is Makefile a shell script?
No it is not. ‘make’ automatically checks which dependencies and their targets need
to be rebuilt and which are the ones to be left untouched based on their
timestamps. However, all of this has to be programmed explicitly while writing a
shell script and in case it is not done, then all the dependencies and their targets will
be rebuilt whenever you run the script, even those that have been left unchanged
since the last build.
3) What does “clean” do in Makefile?
Recompilation of the object files needs to be done when the dependency files or the
header files have changes made more recent than the object file. ‘make clean’
removes all the unwanted object files, those that are no more the updated versions.
4) How does make learn about the last modified files to be compiled?
‘make’ initially checks the validity of the dependencies associated with the program
and if an object file is not yet created, it creates one using the dependencies based
on the set of rules written in the makefile program. If object file and dependencies
already exist, then ‘make’ takes a look at the timestamp for the files by asking the
operating system for the same. If object file has timestamp earlier than that of the
dependencies, then the object file is rebuilt using the set of rules mentioned in the
makefile.
5) What does Cflags in Makefile mean?
Cflags in makefile is a special constant that communicates to ‘make’ how it wants the
dependencies to be compiled. It is basically the list of flags to be passed when the
compilation command is being executed by the makefile.
6) Why do we use -f option with make command?
It is used to read the file mentioned after the -f as the makefile for building the
object file using the set of rules. It is nothing but a flag for the ‘make’ command.

You might also like