EE485A: Introduction to Environments & Tools
for Modern Software Development
Remote Lectures
Until the coronavirus outbreak is contained, the classes will be held fully
remotely
Live lectures on zoom, for active interactions
Lecture slides will be uploaded to class website (Campuswire) ahead of
time
3
Guidelines on Using Zoom
Use the Zoom client instead of the web version
Set user name as your KAIST ID and name (e.g., 20210000 Phil Kim)
Mute the mic except when discussing or asking questions
When you have a question:
Feel free to interrupt the speaker
Raise your hand on Zoom
Write your question on the Zoom Chatroom
4
Instructor
5
Teaching Avengers
Gyuhwan Junghan Bongjoon ByeongIn
Park Yoon Hyun Joung
Jieun Hyunwoo Jinwoo Sungsu
Kim Kang Park Hur
6
Links
1. TA mailing list: ee485.kaist@gmail.com
2. CampusWire: https://campuswire.com/p/G8B8946A2, Code: 6101
1. For course announcements,
2. Assignments
3. Q&A, discussions, etc
4. Lecture notes (check the ”file” folder)
7
Course Overview
Syllabus carefully designed for students taking EE209
Already took EE209? è No need to take this course
Not taking EE209 this semester? è Take it when you’re taking EE209
Grading: letter grade (A-F)
Hands-on practice (60%) + final exam (40%)
No mid-term exam
Designed to be easy
We expect all of you to pass if you regularly attend the classes and follow
the content
You really need to mess it up to fail
8
TA office hours
Send an email to the TAs and make an appointment (either Zoom or in-
person)
ee485.kaist@gmail.com
9
Goals & Recommended Books
Goal: getting familiar with the Linux programming environment
Corollary: feel comfortable with tools for EE209 programming assignments
Tools: shell commands, editor, ctags/cscope, compiler, debugger, source code
management, commands, script languages, trace tools
Recommended books
No textbooks but we have recommendations
William Shotts, “The Linux Command Line”, 2nd edition
Linux commands, Bash shell, ssh/scp, etc.
Free PDF version available for download
Neil Matthew & Richard Stones, Beginning Linux Programming, 4th Edition
Richard Blum & Christine Bresnahan, Linux Command Line and Shell Scripting
Bible
10
Contents
Setting up programming environment
Unix (Linux) and Bash
Using text editor
Executing a simple program
Building a program
11
Linux Programming Environment
Linux
Free, open-sourced operating system (OS)
We use a Ubuntu distribution (Ubuntu Linux)
How to use Linux?
Option1. Visit Haedong Lounge (PC room)
Option2. Remote access to Haedong Lounge (eelab5, eelab6)
Option3. Install Ubuntu on your own PC in a virtual machine
If you use Windows 10, consider windows subsystem for Linux (WSL)
https://docs.microsoft.com/en-us/windows/wsl/install-win10
12
(Don’t Visit) Haedong Lounge
E3-4 Room #1412
https://ee.kaist.ac.kr/en/node/15084
36 machines already set up with your accounts (if you’re taking EE209)
Change your password as soon as possible,
or your account will be automatically banned from access
Consult with a lounge TA for machine
access
Make sure to logout after usage
Don’t turn off machines for remote
accessed users (eelab5,6)
Don’t abuse them for other use
13
Use Ubuntu Linux Command Line Interface
Example: on a Ubuntu machine (Haedong Lounge)
Open Terminal program
14
Lab Machines & Your Accounts
Linux is installed on these machines
eelab1.kaist.ac.kr ~ eelab36.kaist.ac.kr
Remote-accessible machines (always on)
eelab5.kaist.ac.kr, eelab6.kaist.ac.kr
Other machines are supposed to be turned off
Your account should be already created
ID: <your_student_id>
Password: f5k54a’ID’ (but no ‘ in the ID)
e.g, ID: 20210000, passwd: f5k54a20210000
If your ID does not exist or you forgot your password, please contact the TAs
15
Remote Access to Haedong Lounge
You can use tools like ‘ssh’ to access the machines remotely
Unix shell: A command line interpreter
SSH: secure shell (over network)
You invoke a shell on a machine, and securely access it over a network
Network communication on ssh is ‘encrypted’ and ‘authenticated’ (secure)
For Windows users: use PuTTY
Details in the following slide
For MAC OS or Linux: use Terminal
Search and open ‘Terminal’ program.
Type ‘ssh <Student ID>@eelabX.kaist.ac.kr’.
X : 1 ~ 36
16
Remote Access via PuTTY
Download PuTTY program
http://www.putty.org/
Single file: putty.exe
Open putty.exe
Input “Host Name”
eelabX.kaist.ac.kr
Press Open →
Type in password and press ENTER
Enter “yes” at first login
17
Accessing KAIST Machines Off-campus
KAIST allows access from outside via VPN (Virtual Private Network)
Accessing eelab5 from your laptop in KAIST (‘local’ access: no VPN needed)
Accessing eelab5 from our home at Seoul (‘remote’ access: VPN needed)
Install Google OTP on your mobile device
Access https://kvpn.kaist.ac.kr
Login with your KAIST account
Google OTP: type in one time password
PulseSecure runs (or you need to install and run it)
18
Your First Successful Login
You will see a command line interface (CLI)
Shell: we use “bash” shell on eelabX (more details in the next lecture)
Now you can enter a command via typing it
e.g. change your password via command ‘passwd’
19
If you are working remotely …
Remote access could be unstable
Machines could be turned off or network communication could be slow
Lab machines could be unavailable (hardware or network failures)
Keep your important code and files on your own machine
Our recommendation:
Use Linux or WSL on windows10 locally
Test your code on lab machines before submission
How to move files between machines?
Details in the following slide
20
Copying Files between Machines with scp
Download file from lab machine to your machine
$ scp <user name>@<host_name>:<file path> .
‘:’ → end of host name (home folder)
‘.’ → current working directory
e.g. $ scp 20160001@eelab5.kaist.ac.kr:assign1/assign1.c .
Upload file to lab machine
$ scp <file path> <user name>@<host name>:<optional path>
e.g. $ scp assign1.c 20160001@eelab5.kaist.ac.kr:assign1/
Copy many files
e.g. $ scp *.c 20160001@eelab5.kaist.ac.kr:assign1/
‘*’ → matches any characters more than zero
FYI, scp uses the same ‘protocol’ as ssh
Download is secure – encrypted and authenticated
21
Linux (OS) and Shell
What is OS?
system software that helps applications run by providing services that require
interacting with hardware, by protecting from other (malicious) program, etc.
“kernel”: core program that manages resources of a computer system
“system function”: request a “privileged” service to kernel
Shell: takes keyboard commands and passes them to OS to carry out
sh (Bourne shell), bash (bourne again sh), ksh, csh/tcsh,
Why shell? make difficult tasks possible!
GUI: make easy tasks easy
Shell (e.g., Bash) C Applications
Shared C Functions
Linux System Functions
Linux Kernel
Computer hardware
22
Sample Bash Commands
More commands in bash_manual.pdf file
Not comprehensive, but should be enough in most cases
Will revisit them later
Command Description
man <function name> open manual page
cd <directory name> change directory
ls [-al] list files in the directory
mkdir <directory name> make directory
rmdir <directory name> remove directory
less/cat/more <file name> print file content
cp <source> <target> copy source file to target
mv <source> <target> rename source file to target
rm <file name> remove file
Be very careful using 'rm' command
23
Text Editor for Programming
We use text editors to write a program
Popular text editors for programming
Emacs, Vim, Visual Studio Code, Sublime, Atom …
Useful functionalities
Syntax highlighting – easy keyword check
Indentation (e.g., ‘tab’ to align code)
Easy to use tools to analyze errors in code
Debugging (gdb), compiling (make), code hierarchy, …
Hotkeys for many functionalities
We have a separate lecture on the editors
24
Example: Emacs
Emacs: one of the most popular code editors on Linux
Open Terminal
Type command to open Emacs editor
emacs <filename>
e.g. emacs hello.c
Start programming with Emacs
You can remove “Welcome message”
Click on “Never show it again.”
Then click “Dismiss this startup screen”
25
Simple Terminal vs X Window System
What is X Window System?
A Window system on UNIX-like OS
Provides GUI environment
Emacs on X Window System
Emacs on Simple Terminal
26
How To Run Linux Apps on X Window?
Local machine must support X window
If you use Linux on local machine, you’re likely to run X window system already
If you use WSL, install/run helper app like ‘VcXsrv’ first
Remote login with –X option
ssh –X eelab6.kaist.ac.kr // called X forwarding
emacs hello.c & // emacs now runs in an X window
‘&’ means that emacs runs as a background process (vs. foreground
process)
Why run it as background?
Shell can accept the next command even before the previous one has
not finished
Very useful for editing, compiling, debugging at the same time
27
Emacs Hotkeys
File, window Text edit
Hotkey Description Hotkey Description
Ctrl-x Ctrl-s Save file Ctrl-k Cut line
Ctrl-x-c Close file Mark cursor
Ctrl-[SPACE]
Ctrl-x-f <file> Open file from editor (move with arrow key)
Split window Ctrl/alt-w cut/copy region
Ctrl-x 2/3
vertically/horizontally Ctrl-y paste cut/copied region
Ctrl-x o Move to different window Ctrl-s/r <string> search/recursive string
Ctrl-x 1/0 Close other/this window
Special
Ctrl-x u OR Ctrl-/ undo
Ctrl-g abort command
28
Building a C Program
hello.c
#include <stdio.h> • Source code
int main(void)
{
• C language
/* Write "hello, world\n" to stdout. */ • Contains
printf("hello, world\n"); preprocessor
return 0; directives
}
Compile and execute hello.c
ee209@ubuntu:~$ gcc209 hello.c -o hello
ee209@ubuntu:~$ ./hello
hello, world
gcc209 is a script that executes
gcc -Wall -Werror -ansi -pedantic -std=c99
29
Steps to Make Executable File
Shortcut
hello.c gcc209 hello.c -o hello hello
C Preprocessor Linker
gcc209 -E hello.c > gcc209 hello.o -lc -o
hello.i hello
hello.i hello.o libc.a
C Compiler C Assembler
gcc209 -S hello.i hello.s gcc209 -c hello.s
30
Preprocess C Code
hello.i
C Preprocessor
gcc209 -E hello.c > hello.i • Source code
• C language
• Contains declaration
of printf() function
• Missing definition of
… printf() function
int printf(char *format, …);
… • Remove comments
int main(void)
{
printf("hello, world\n");
return 0;
}
31
Compile Assembly Language
hello.s
C Compiler
gcc209 -S hello.i
• Source code
• Assembly language
specific to computer
architecture
• Missing definition of
.section .rodata movl %esp, %ebp printf() function
cGreeting: pushl %cGreeting
.asciz "hello, world\n" call printf
.section .text addl $4, $esp
.global main movl $0, %eax
.type main, @function movl %ebp, %esp
main: popl %ebp
puchl %ebp ret
32
Generate Object File
hello.o
C Assembler
gcc209 -c hello.s • Object file
• Machine language
• Unreadable by
human
• Missing definition of
printf() function
• libc.a = library
containing machine
… 100101000110100100100 … language definition
of printf() function
(and many others)
33
Generate Executable Binary
hello.o
…100101000110100100100… • Executable
libc.a • Machine language
• libc.a = library
…11100100000100100110…
containing machine
language definition
of printf() function
Linker
(and many others)
gcc209 hello.o -lc -o hello
hello
20160001@eelab1:~$ ./hello
hello, world
34
Shortcut of All Processes
Shortcut
hello.c gcc209 hello.c -o hello hello
C Preprocessor Linker
gcc209 -E hello.c > gcc209 hello.o -lc -o
hello.i hello
hello.i hello.o libc.a
C Compiler C Assembler
gcc209 -S hello.i hello.s gcc209 -c hello.s
35
gcc209 vs. gcc?
gcc209 is a special script made for EE209
Script: a text file that contains commands to execute a series of tasks
gcc209 adds a number of options to catch improper programming
e.g. warns unused variable, use variable without initializing it, etc.
You can make this script by yourself using emacs editor (or whatever
editor you like)
$ emacs gcc209
#!/bin/bash
gcc -Wall -Werror -ansi -pedantic -std=c99 "$@"
Make this script executable:
$chmod +x gcc209
Move this file to folder that can be accessed globally
$sudo mv gcc209 /usr/bin/gcc209
36
Assignment for Lecture 1
1. ssh into one of the lab machines (eelab5 or eelab6)
2. Run emacs (preferably as background process in X window) or vim or any
text editor at your choice.
3. Type in the C code for hello.c (that prints “hello, world”)
4. Compile it with gcc209 and name the executable as hello
5. Run hello
Main to-do: take a snapshot of these steps and upload it (must be JPG) to
the course submission site
One picture (only jpg is permitted) that shows all these commands
Deadline: 10:25am on March 11 (next class)
All assignments are due before the start of the next class in the following week
Submission link available at KLMS!!!!
37
38