In Lab 1 Slide

You might also like

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

March 22, 2023

Operating System - Lab 1

Introduction to
Linux Programming
TA - Nhu Huynh
Contact information
For information or any inquires, please contact via

Huynh Ngoc Nhu


Email: nhu.huynh1142002@hcmut.edu.vn
Tagged your subject: [CO2018-232]

Telegram: @nhuhuynhdn (urgent case)


Grading
20% 30% Attendance

Submit in-lab exercise


4 labs
Assignment on time to verify your
Homework exercise
attendance

DISQUALIFIED FROM FINAL EXAMS:

Lab score < 4


Any component score = 0
Lab 1
Lab 2
Introduce to Linux
Process
Programming

Overall Lab 3 Lab 4

4 labs Synchronization Scheduling


Welcome to our first lab!

1. Linux introduction 2. Bash Script 3. C development 4. GNU Toolchain


Familiar with Linux using Use Linux Bash Script to C compilation process GNU Make
Command Line Interface perform complex tasks GNU Debugger

In-lab exercise Compulsory exercise


Compulsory exercise
9:30 11:00
Prerequisites
Must: Install & setup Linux OS (Ubuntu) on your personal computer.
Please read the detail guideline attached.

Opt1: Install Linux with VirtualBox. Opt2: Install WSL on Window: lightweight, fast
(May take you 30 mins or even hours) startup but lacking full Linux desktop experience.
Terminal &
Command Line
To launch Linux terminal:
- Ctrl + Alt + T
- Click Ativities->Type “Terminal”
Update/Install
Your very first command!

With Ubuntu, to update/upgrade all the installed


packages:
sudo apt-get update/upgrade (root)
To install a new package:
sudo apt-get install <package-name>

Note: Please update before installing any new package!


Try to install “nano”, “”vim”, “make”, “gcc”
Get to know
Linux commands
Resource:
<Lab_1_HK232.pdf>
https://www.geeksforgeeks.org/cd-
command-in-linux-with-examples/
Linux Command cheat-sheet:
https://cheatography.com/davechild/c
heat-sheets/linux-command-line/
Learn Linux Command by playing:
https://linuxsurvival.com/
Learn Vim by playing:
https://vim-adventures.com/
Basic
Command
File Permission
To show the permission files/folders:
ls -l
File Permission
Change permission of group(g), other
To change the permission: (o) and all users (a):
chmod <access_mode> file(s)/folders - chmod g+rw filename - add read and write
The <access_mode> can be one of these formats: permission for group.
Symbolic: [uago] [+-=][rwx] - chmod a=r filename - give only read
permission for all users.
Octal: [0-7][0-7][0-7]
- chmod o-w filename - remove write
permission for others.

The <access_mode> in symbolic:


Change permission of owner(u):
- chmod +rx filename: add read & execute permission for owner
- chmod u+rx filename: add read & execute permission for owner
Example:
- chmod -w filename: remove write permission for owner [Symbolic] chmod 777 filename
- chmod =r filename: give only read permission for owner [Octal] chmod a=rwx filename
Exercise 1
1. Create a New Directory with <Your Student-ID>.
2. In Folder <Your Student-ID>:
a. Create a New File named "nano_guide.txt".
b. Edit File "nano_guide.txt" with the given paragraph*.
c. View the Content of "nano_guide.txt".
d. Copy "nano_guide.txt" to a New File "nano_tips.txt".
3. Move "nano_tips.txt" to your home directory.
4. List the Content of <Student-ID> Directory.
5. Change the Permission of "nano_guide.txt" to Read Only.
6. Change the Permission of All Files in <Student-ID> Directory to ReadnWrite for Owner.
7. List All Commands That Have Been Run from That Terminal Session and Save to
“<StudentID>-history.txt".
Exercise 1
Edit File "nano_guide.txt" with the given paragraph:

//Your student ID
To open a file in Nano, type nano filename in the terminal.
Use arrow keys to navigate through the text.
To start typing or editing, simply begin typing.
Press Ctrl + O to save the file.
Press Ctrl + X to exit Nano.
If prompted to save changes, press Y for yes or N for no.
To search for a word, press Ctrl + W, type the word, and press Enter.
Press Ctrl + G for help and see other available commands.
Nano displays common actions at the bottom for easy reference.
Welcome to our first lab!

1. Linux introduction 2. Bash Script 3. C development 4. GNU Toolchain


Familiar with Linux using Use Linux Bash Script to C compilation process GNU Make
Command Line Interface perform complex tasks GNU Debugger

Exercise 1 - 9:30 AM
Submit <StudentID>.zip:
Screenshots
<StudentID>-history.txt
Linux Kernel & Shell

Linux system = Kernel + GNU system utilities & Shell is the interface helping user
libraries + other management scripts + installation communicate with the kernel.
scripts.
Bash
BASH is a default command line shell interpreter on many Linux OS.
A bash script file is a text file with extension .sh
To find where the bash interpreter locates, we type:
$ which bash
To declare the interpreter, we put “#!/bin/bash” in the first line of the script
file.
Read more in the “Lab_1_HK232”, submit your file <calc.sh> for exercise 3.6.
Welcome to our first lab!

1. Linux introduction 2. Bash Script 3. C development 4. GNU Toolchain


Familiar with Linux using Use Linux Bash Script to C compilation process GNU Make
Command Line Interface perform complex tasks GNU Debugger

In-lab exercise - 9:30 AM Compulsory 3.6 - 11 AM


Submit <StudentID>.zip: Submit <StudentID>.zip:
Screenshots Screenshots
<StudentID>-history.txt calc.sh
C Program Compilation Process
Makefile
Makefiles are used to
automate, control the
compilation process.

A Makefile consists of a
set of rules, includes:
targets: prerequisites
command
command
Makefile
Read more in the Lab file.
Submit your file
<Makefile>, <calc> for
exercise 5.3.

When running “$ make blah”, it will run as following steps:


Make is given blah as the target, so it first searches for this target
blah requires blah.o, so make searches for the blah.o target
blah.o requires blah.c, so make searches for the blah.c target
blah.c has no dependencies, so the echo command is run
The gcc command is then run, because all of the blah.o dependencies are finished
The top gcc command is run, because all the blah dependencies are finished
That's it: blah is a compiled c program
Welcome to our first lab!

1. Linux introduction 2. Bash Script 3. C development 4. GNU Toolchain


Familiar with Linux using Use Linux Bash Script to C compilation process GNU Make
Command Line Interface perform complex tasks GNU Debugger

In-lab exercise - 9:30 AM Compulsory 3.6 - 11 AM Compulsory 5.3 - Homework


Submit <StudentID>.zip: Submit <StudentID>.zip: Screenshots
Screenshots Screenshots
makefile, calc
<StudentID>-history.txt calc.sh
I HOPE WE HAVE AN
AMAZING SEMESTER!
Any questions left?

Write lab report <Student-ID.pdf>with clear screenshots for each


exercise.
Compress all files into a ZIP archive named with your student ID
(<Student-ID.zip> and submit it before Monday, 25 March 11:59 PM.

You might also like