Professional Documents
Culture Documents
Until the coronavirus outbreak is contained, the classes will be held fully
remotely
3
Guidelines on Using Zoom
Set user name as your KAIST ID and name (e.g., 20210000 Phil Kim)
4
Instructor
5
Teaching Avengers
6
Links
1. TA mailing list: ee485.kaist@gmail.com
7
Course Overview
Not taking EE209 this semester? è Take it when you’re taking EE209
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
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
Recommended books
No textbooks but we have recommendations
Neil Matthew & Richard Stones, Beginning Linux Programming, 4th Edition
Richard Blum & Christine Bresnahan, Linux Command Line and Shell Scripting
Bible
10
Contents
Building a program
11
Linux Programming Environment
Linux
Free, open-sourced operating system (OS)
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
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
13
Use Ubuntu Linux Command Line Interface
14
Lab Machines & Your Accounts
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)
X : 1 ~ 36
16
Remote Access via PuTTY
Open putty.exe
Press Open →
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)
Access https://kvpn.kaist.ac.kr
Login with your KAIST account
18
Your First Successful Login
19
If you are working remotely …
Our recommendation:
20
Copying Files between Machines with scp
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
Shared C Functions
Linux System Functions
Linux Kernel
Computer hardware
22
Sample Bash Commands
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
23
Text Editor for Programming
Useful functionalities
Syntax highlighting – easy keyword check
24
Example: Emacs
emacs <filename>
25
Simple Terminal vs X Window System
26
How To Run Linux Apps on X Window?
Shell can accept the next command even before the previous one has
not finished
27
Emacs Hotkeys
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
}
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
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
C Compiler C Assembler
gcc209 -S hello.i hello.s gcc209 -c hello.s
35
gcc209 vs. gcc?
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 "$@"
36
Assignment for Lecture 1
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
37
38