CPE-3411-Lab No 1
CPE-3411-Lab No 1
Name: ___________________________
Reg. #: ___________________________
Section:___________________________
© Copy Rights, Department of Electrical and Computer Engineering, CUST Islamabad
All Rights Reserved
1
List of Labs
Lab 02 Working with Navigation, and File & Directory Handing Commands 25
Lab 05 Managing Processes, and Writing, Compliling & Executing C++ on Linux 53
Lab 06 Using Fork, Exec, Wait & Exit System-Calls for Creating Chile Processes 68
Lab 11 Writing & Executing Shell Scripts, I/O, Variables, and Operators 99
2
Lab No. 01
Installing Linux Distribution on Virtual Machine,
Command-line Interface
Objective:
This lab will introduce the Linux Operating System to you. You will learn the how to createVM
using Virtual-Box, Installing Ubuntu on VM and the basic syntax of Linux Commands.
Activity Outcomes:
On completion of this lab students will be able to:
Introduction of Linux OS, Linux Distros and Virtual Machines
Creating VM in Virtual-Box
Installing Ubuntu on VM
Writing basic commands in CLI
Instructor Note:
As pre-lab activity, read Chapter 1 to 6 from the book “The Linux Command Line”, William E.Shotts,
Jr.
1) Useful Concepts
Operating System
An operating system (OS) is a program that interacts as interface between a user and ans a computer
system software. It manages computer hardware, software resources, and provides common services for
computer programs. Primary Goals of an Operating System include: To provide ease of use,
convineance and throughput. The main functions perform by operating system can be categorized as:
Process management, Resource Management, Stroge Management, Memory Management and Security
Management.
Why Linux
Linux is among the most popular operating systems. The main reasons for this popularity are: Free and
open source, Stable and Reliable, Secure, and Flexible.
Linux History
Linux was originally developed for personal computers based on the Intel x86 architecture, but has
since been ported to more platforms than any other operating system. In the early 1990s, Finnish
computer science student Linus Torvalds began hacking on Minix, a small, Unix−like operating system
for personal computers then used in college operating systems courses. He decided to improve the main
software component underlying Minix, called the kernel, by writing his own. (The kernel is the central
component of any Unix−like operating system.) OnSeptember 1991, Torvalds published the first
version of this kernel on the Internet, calling it "Linux" (a play on both Minix and his own name).(7)
When Torvalds published Linux, he used the copyleft software license published by the GNU Project,
the GNU General Public License. Doing so made his software free to use, copy, and modify by
anyone−−provided any copies or variations were kept equally free. Torvalds also invited contributions
3
by other programmers, and these contributions came; slowly at first but, as the Internet grew,
thousands of hackers and programmers from around the globe contributed to his free software project.
The Linux software was immensely extended and improved so that the Linux−based system of today is
a complete, modern operating system, which can be used by programmers and non−programmers .
Popularity:
Because of the dominance of the Linux-based Android on smartphones, Linux also has
the largest installed base of all general-purpose operating systems. Although Linux is used by only
around 2.3 percent of desktop computers, the Chromebook, which runs the Linux kernel-based Chrome
OS, dominates the US K–12 education market and represents nearly 20 percent of sub
$300 notebook sales in the US. Linux is the leading operating system on servers (over 96.4% of the top
1 million web servers' operating systems are Linux), leads other big iron systems such as mainframe
computers, and is the only OS used on TOP500 supercomputers (since November 2017, having
gradually eliminated all competitors).
Linux also runs on embedded systems, i.e. devices whose operating system is typically built into
the firmware and is highly tailored to the system. This includes routers, automation controls, smart
home technology, televisions (Samsung and LG Smart TVs use Tizen and WebOS, respectively)
, automobiles (for example, Tesla, Audi, Mercedes-Benz, Hyundai, and Toyota all rely on
Linux), digital video recorders, video game consoles, and smartwatches. The Falcon 9's and the Dragon
2's avionics use a customized version of Linux.
Linux Distribution
Linux is open-source, free to use kernel. It is used by programmers, rganizations, profit and non-profit
companies around the world to create Operating systems to suit their individual requirements.To
prevent hacking attempts, many organizations keep their Linux operating systems private. Many others
make their variations of Linux available publicly so the whole world can benefit at large. These
versions/ types /kinds of Linux operating system are called Distributions. A list of most popular Linux
distributions is given below:
Another popular enterprise based Linux Distribution is Red Hat Enterprise.It has
evolved from Red Hat Linux which was discontinued in 2004. It is a commercial
Distro and very popular among its clientele.
4
This is the third most popular desktop operating system after Microsoft Windows
and Apple Mac OS. It is based on the Debian Linux Distribution, and it is known as
its desktop environment.
Another Linux kernel based Distro, Fedora is supported by the Fedora project, an
endeavor by Red Hat. It is popular among desktop users. Its versions are known for
their short life cycle.
In this course, we will use the Ubuntu distro. Ubuntu is a popular and to use graphical Linux distro. It
was developed and released by Canonical Ltd. in 2004. It is freely available and can be downloaded
from http://www.ubuntu.com/download/desktop.
Installing Ubuntu
Before discussing the options available to install Ubuntu, we discuss the basic system requirement.
It is recommended to Ubuntu should be installed on a system that has a 2 GHz dual core processor
with 2GB RAM and 25GB of free hard disk space. There are many ways to use Ubuntu. It can be
installed on a system as a stand-alone OS. Similarly, it can be installed as multi-boot system where it is
installed on a system that already has any other OS like windows. Further, it can also be used without
installing from a bootable USB. However, in this course we will run the Ubuntu on virtual machine. To
create virtual machine we will use Oracle VM Virtual-box. In the following, first we give an overview
of Virtual-Box and then discuss the installation process of Ubuntu on VM.
Download and Install Virtual Box: Download Virtual box using this link Depending on your
processor and OS, select the appropriate package. In our case, we have selectedwindows with AMD.
5
Once the download is complete, Open setup file and follow the steps below:
Click On next
6
Select Desktop icon and click on next, now click on yes
7
Now installation of the virtual box will start. Once complete, click on Finish Button to start Virtual Box
8
-
Download Ubuntu:
Visit this link to download Ubuntu.
9
In next window, give the name of your OS which you are installing in virtual box. And select OS
like Linux and version as Ubuntu 32 bit. And click on next
Now Allocate Ram Size To your Virtual OS. I recommended keeping 1024mb (1 GB) ram to run
Ubuntu better. And click on next
10
.
Now To run OS in virtual box we have to create virtual hard disk, click on create a virtual hard drive
now and click on create button. The virtual hard disk is where the OS installation files and
data/applications you create/install in this Ubuntu machine will reside
11
Click on dynamic allocated and click on next. This means that the size of the disk will increase
dynamically as per requirement.
Allocate memory to your virtual hard drive .8GB recommended. Click on create button.
12
Now you can see the machine name in left panel
13
Select the Folder Option
14
Select the Ubuntu iso file
Click Startup
You have an option to Run Ubuntu WITHOUT installing. In this tutorial will install Ubuntu
15
Click continue
.
Select option to erase the disk and install Ubuntu and click on install now. This option installs Ubuntu
into our virtual hard drive which is we made earlier. It will not harm your PC or Windows installation
16
Select your location for setting up time zone, and click on continue
Select your keyboard layout, by default English (US) is selected but if you want to change then, you can
select in the list. And click on continue
17
Select your username and password for your Ubuntu admin account. This information has been needed
for installing any software package into Ubuntu and also for login to your OS. Fill up your details and
tick on login automatically to ignore login attempt and click on continue
Installation process starts. May take up to 30 minutes. Please wait until installation process completes.
18
After finishing the installation, you will see Ubuntu Desktop.
The Command Line Interface (CLI), is a non-graphical, text-based interface to the computer system,
where the user types in a command and the computer then successfully executes it. The Terminal is the
platform or the IDE that provides the command line interface (CLI) environment to the user. The CLI
terminal accepts the commands that the user types and passes to a shell. The shell then receives and
19
interprets what the user has typed into the instructions that can be executed by the OS (Operating
System). If the output is produced by the specific command, then this text is displayed in the terminal.
If any of the problems with the commands are found, then some error message is displayed.
We can open the terminal by typing Ctrl + Alt + T short-key or by right-clicking the mouse and
selecting the Open New Terminal option. The terminal window looks like given below.
A command is an instruction given by a user telling a computer to do something, such a run a single
program or a group of linked programs. Commands are generally issued by typing them in at the c
command line (i.e., the all-text display mode) and then pressing the ENTER key, which passes themto
the shell. A shell is a program that reads commands that are typed on a keyboard and then executes
(i.e., runs) them. Shells are the most basic method for a user to interact with the system.
Options and Arguments: This brings us to a very important point about how most commands work.
Commands are often followed by one or more options that modify their behavior, and further, by one or
more arguments, the items upon which the command acts. So most commands look kind of like this:
2) cal Command: This command is used to display the calendar of the year or the
particular month of calendar year.
$cal <year> or $cal <month> <year>
3) who Command: It is used to display who are the users connected to our computer currently.
$who –option‟s
Common Options:
H–Display the output with headers
b–Display the last booting date or time or when the system was lastly rebooted
6) man Command: It help us to know about the particular command and its options & working. It is
like„help‟ command in windows .
$man <command name>
7) df Command: is used to see the current amount of free space on your disk drives
$df
8) free Command: Likewise, to display the amount of free memory, enter the free command.
$free
9) exit Command: We can end a terminal session by either closing the terminal emulator window, or
by enteringthe exit command at the shell prompt
21
$exit
Activity 1:
In this activity, you are required to perform tasks given below:
Display the current date
Display the calendar for the current month
Display the calendar of 2012
Display the calendar of Feb 2015
Solution:
22
Activity 2:
In this activity, you are required to perform tasks given below:
23
3) Graded Lab Tasks
Note: The instructor can design graded lab activities according to the level of difficult and complexity
of the solved lab activities. The lab tasks assigned by the instructor should be evaluated in the same
lab.
Lab Task 1:
In GUI open the Libre Office writer tool create a document that contains information about your
favorite place. Try the following short- keys while formatting the document.
24
LABORATORY SKILLS ASSESSMENT (Psychomotor)
Total Marks: 100
Marks Obtained
LABORATORY SKILLS ASSESSMENT (Affective)
Total Marks: 40
Marks Obtained