Linux Terminal - Compilers
Linux Terminal - Compilers
A shell (a.k.a. command language interpreter) is the software that handles the CLI. Two commonly
used shells are
Shells are the outermost layer of the operating system (OS) and are often separated from the
underlying OS kernel. A shell operates like an application and can be replaced. Because the shell is
only one layer above the OS, users can perform operations that are not available in other interface
types. However, shell users are required to know the syntax of a scripting language. Most command
line shells save sequences of commands for reuse in a script, which is the foundation of basic
systems management automation.
Pg. 1 of 6
University of Technology, Jamaica Operating Systems
School of Computing & Information Technology CIT3002
Used to identify whether a command exist based on the location of executable files within
the PATH environment.
PATH is an environmental variable that tells the shell and other programs where to search
for executable file. To view content of PATH variable use:
3 Compilers in Linux
One of the advantages of using Linux is that you can compile and execute your own program from
the terminal. We will now examine how Linux works with program from C, C++, Java, and python.
Before compiling you need to check to see if either of these compilers are present, using commands
from section 2 above. Bellow are some other examples of verifying if installed.
Pg. 2 of 6
University of Technology, Jamaica Operating Systems
School of Computing & Information Technology CIT3002
Compilers are not usually installed, therefore follow these steps in Ubuntu to utilize gcc or g++
I will you which, but you can use any other command you are comfortable with.
Example of results:
You can use any of the following syntax below to compile c program, both will create a
default executable a.out
Pg. 3 of 6
University of Technology, Jamaica Operating Systems
School of Computing & Information Technology CIT3002
Preceding can be accomplished another way by compiling (pre-processing, compiling, and
assembling) and linking processes in a single step by using the -g to produce debugging
information and -o option to create an output file with a different name.
You can also use the make command instead of cc or gcc to compile a C program
Above creates an output file called hello, but a file called hello.c must exist
The primary Java compiler from Oracle Corporation is called javac. To check if already
installed use:
You may even notice that it is not installed, if you get the following error:
Install using one of sudo above; once installed you can compile.
javac will generate a hello.class file and that is the file you run using
Pg. 4 of 6
University of Technology, Jamaica Operating Systems
School of Computing & Information Technology CIT3002
There is no compilation required for python. If you have a file called hello.py with the contents
below, just use to execute.
4 Activity
1. Modify fifo.c below to accept arrival time for process
#include<stdio.h>
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20):");
scanf("%d",&n);
Pg. 5 of 6
University of Technology, Jamaica Operating Systems
School of Computing & Information Technology CIT3002
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
}
avwt/=i;
avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);
return 0;
}
5 References
Gillis, A. S. (2021, August 18). command line interface (CLI). Retrieved from TechTarget:
https://searchwindowsserver.techtarget.com/definition/command-line-interface-CLI
Pg. 6 of 6