0% found this document useful (0 votes)
24 views28 pages

CPE-3411-Lab No 1

The document is a laboratory manual for CPE-3411: Operating Systems Lab, detailing the course structure, intended learning outcomes, and assessment policies. It covers various topics including Linux installation, command-line interface, process management, and shell scripting, with a list of labs and their objectives. The manual also provides insights into Linux history, distributions, and basic command usage.

Uploaded by

mohammaduzair726
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views28 pages

CPE-3411-Lab No 1

The document is a laboratory manual for CPE-3411: Operating Systems Lab, detailing the course structure, intended learning outcomes, and assessment policies. It covers various topics including Linux installation, command-line interface, process management, and shell scripting, with a list of labs and their objectives. The manual also provides insights into Linux history, distributions, and basic command usage.

Uploaded by

mohammaduzair726
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Laboratory Manual

CPE-3411: Operating Systems Lab

Name: ___________________________
Reg. #: ___________________________
Section:___________________________
© Copy Rights, Department of Electrical and Computer Engineering, CUST Islamabad
All Rights Reserved

Prepared by Engr. Amir Habib


Lab Contents:
Installating Linux Distrubutions on Virtaul Machnes; Linux Command-line Interface: Basic Syntax, Navigation
Commands, File & Directory Handling Commands, I/O Redirection, Controlling Access to Files, Package
Management, Text-processing, Pipelining, Process Management; Writing & Compiling C++ on Linux; Process
Management: Creating Child Processes, IPC with Shared-Memory & Message-Passing, Multithreading,
Synchronization; Shell Scripting: Fundamentals, I/O, Variables, Operators, Conditional Statements, Looping
Statements, Arrays, and Functions.
Student Outcomes (SO)
S.# Description
Apply knowledge of computing fundamentals, knowledge of a computing specialization, and mathematics,
1 science, and domain knowledge appropriate for the computing specialization to the abstraction and
conceptualization of computing models from defined problems and requirements
Identify, formulate, research literature, and solve complex computing problems reaching substantiated
2 conclusions using fundamental principles of mathematics, computing sciences, and relevant domain
disciplines
Create, select, adapt and apply appropriate techniques, resources, and modern computing tools
4
to complex computing activities, with an understanding of the limitations
Intended Learning Outcomes
Blooms Taxonomy
Sr.# Description SO
Learning Level
CLO -5 Operate basic services and functionality of operating systems. Applying 1
CLO -6 Compose Linux commands using Shell scripting. Applying 1,4
CLO -7 Implement the concepts of process management. Applying 2,4
Lab Assessment Policy
The lab work done by the student is evaluated using rubrics defined by the course instructor, viva-voce, project
work/performance. Marks distribution is as follows:
Assignments Lab Mid Term Lab Terminal Total
Exam Exam
25 25 50 100
Note: Midterm and Final term exams must be computer based.

1
List of Labs

Lab # Main Topic Page #

Lab 01 Installing Linux Distribution on Virtual Machine, Command-line Interface, 3


and Basic Command Structure

Lab 02 Working with Navigation, and File & Directory Handing Commands 25

Lab 03 Controlling Access to Files, and Managing Packages using Commands 33

Lab 04 Text Processing, and Pipelining 46

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 07 Inter-Process Communications using Shared-Memory & Message-Passing 78

Lab 08 Creating Multithreaded Applications 83

Lab 09 Mid Term Exam

Lab 10 Synchronization: Two-Process Solutions, MUTEX, and Semaphore 88

Lab 11 Writing & Executing Shell Scripts, I/O, Variables, and Operators 99

Lab 12 Writing Shell Scripts using Conditinal-Statements, and Loops 110

Lab 13 Using Arrays, and Functions in Shell Scripts 117

Lab 14 Final Term Exam

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:

Deepin is a Linux desktop-oriented operating system derived from Debian,


supporting laptops, desktops, and all-in-ones. It aims to provide a beautiful, easy-to-
use, safe, and reliable operating system to global users.
It is one of the most popular Desktop Distributions available out there. It launched
in 2006 and is now considered to be the fourth most used Operating system in the
computing world.

This Linux Distro is popular amongst Developers. It is an independently developed


system. It is designed for users who go for a do-it-yourself approach.

Slackware aims for design stability and simplicity

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.

Installing Linux using Virtual Machine


This is a popular method to install a Linux operating system. The virtual installation offers you the
freedom of running on an existing OS already installed on your computer. This means if you have
Windows running, then you can just run Linux with a click of a button.Virtual machine software like
Oracle VM can install Linux on Windows in easy steps. Let us look at them.
The following diagram shows the steps required to install 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

Select you’re the directory to install VirtualBox and click on next

6
Select Desktop icon and click on next, now click on yes

Click On install-to-install Linux on Windows.

7
Now installation of the virtual box will start. Once complete, click on Finish Button to start Virtual Box

The virtual box dashboard looks like this

8
-

Download Ubuntu:
Visit this link to download Ubuntu.

You can select 32/64-bit versions as per your choice.


Create a Machine in Virtual Box: Open Virtual box and click on new button

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

select VHD (virtual hard disk) option and click on next.

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

So a Machine (PC) with 8GB Hardisk, 1GB RAM is ready.


How to Install Ubuntu
Select the Machine and Click on Start

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.

Writing Linux Commands

Command Line Interface

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.

Basic syntax of Linux Commands

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:

$command -optioins arguments


Most commands use options consisting of a single character preceded by a dash, for example, “-l”, but
many commands, including those from the GNU Project, also support long options, consisting of a
word preceded by two dashes. Also, many commands allow multiple short options to be strung
together.
Command History:Most Linux distributions remember the last 500 commands by default. Press the
down-arrow keyand the previous command disappears.

Some Basic Linux Commands


1) Date Command: This command is used to display the current data and time.
$date or $date +%ch
20
Common Options:
a = Abbreviated weekday. A = Full weekday.
b = Abbreviated month.
B = Full month.
c = Current day and time.
C = Display the century as a decimal number. d = Day of the month.
D = Day in „mm/dd/yy‟ format
h = Abbrevated month day.

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

4) whoami Command: Display the details of the current working directory.


$whoami

5) clear Command: It is used to clear the screen.


$clear

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

2) Solved Lab Activities


Sr.No Allocated Time Level of Complexity CLO Mapping
1 10 Medium CLO-5
2 10 Medium CLO-5

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:

 Display the amount of free storage on your machine


 Display the amount of free memory on your machine
 Display the user name of the current user
 Open the man of date free command
Solution:

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

Criteria Level 1 Level 2 Level 3 Level 4


Score (S)
(Max Marks) 0% ≤ S < 50% 50% ≤ S< 70% 70% ≤ S< 90% 90%≤ S ≤100%
Procedural Selects Selects and Selects and applies Selects and applies
Awareness inappropriate applies partially considerably completely
(20) Linux commands, appropriate Linux appropriate Linux appropriate Linux
shell scripting commands and commands and commands and
techniques, or techniques techniques. techniques
process
management
methods.
Practical Makes major Makes numerous Makes minor non- Executes Linux
Implementation critical errors in critical errors in critical errors in commands and
(20) executing Linux executing executing Linux manages processes
commands, commands and commands and correctly with no
scripting, and process system operations. errors.
system processes. management.
Process Program logic Program logic has Program logic is Program logic is
Management and contains major some errors with mostly correct but completely correct
Shell Scripting errors with occasional may contain with no
(20) incorrect or contradictions in occasional contradictions or
contradictory process redundancy or redundant
script flow. execution. minor errors. processes.
Syntax Program does not Program partially Program adequately Program fully follows
Correctness and follow proper follows proper follows proper proper syntax,
Results (20) syntax for Linux syntax, producing syntax, producing producing accurate
commands and correct results for correct results for results for all inputs.
shell scripting, few inputs. most inputs.
leading to
incorrect outputs
Use of OS Tools Uses OS tools (like Uses OS tools Uses OS tools with Uses OS tools
(10) terminal, process with some considerable proficiently with a
manager) with competence. competence. high degree of
limited competence.
competence.
Safety (10) Requires constant Requires some Follows system Routinely follows
reminders to reminders to safety procedures system safety
follow system follow system with minimal procedures.
safety procedures safety reminders.
(e.g., file procedures.
permissions,
process handling).

Marks Obtained
LABORATORY SKILLS ASSESSMENT (Affective)
Total Marks: 40

Criteria (Max. Level 1 Level 2 Level 3 Level 4 Score


Marks) 0% ≤ S < 50% 50% ≤ S < 70% 70% ≤ S < 90% 90% ≤ S ≤ 100% (S)
Attitude & Shows little Participates Engages actively in Highly motivated,
Engagement interest in lab occasionally but most lab activities participates
(5) activities; does lacks enthusiasm with interest. enthusiastically, and
not participate and consistency. shows a proactive
actively. approach
Responsibility Frequently Occasionally late Submits work on time Always punctual,
& Punctuality misses deadlines or misses and attends lab meets deadlines, and
(5) and is often late deadlines but tries sessions regularly. takes full responsibility
to lab sessions. to catch up. for assigned tasks.
Collaboration Rarely Works with team Cooperates well, Actively engages in
& Teamwork collaborates, members contributes teamwork, supports
(10) struggles to work occasionally but effectively, and peers, and
in a team, and struggles with maintains demonstrates
does not communication. professional excellent
contribute interactions. collaboration.
effectively.
Communicatio Struggles to Communicates Presents ideas Communicates clearly,
n& explain ideas with some effectively with minor confidently, and
Presentation concepts, clarity but lacks issues in clarity or effectively in all
Skills (10) unclear confidence or structure. aspects of lab work.
verbal/written coherence.
communication.
Report Quality Report contains Report is Report is well Report is well
(10) many errors. somewhat organized and organized and
organized with cohesive but contains cohesive and contains
some spelling or some grammatical no grammatical errors.
grammatical errors. Presentation seems
errors. polished.

Marks Obtained

You might also like