System Programming Chapter 2 Programming Environment September 6
System Programming Chapter 2. Programming Environment September 6, 2016 Jongmoo Choi Dept. of Software Dankook University choijm@dankook. ac. kr http: //embedded. dankook. ac. kr/~choijm
Chapter Objectives Understand the features of Linux Find out how to access Linux Learn how to use the commands in Linux Learn how to make programs in Linux 2
Linux Introduction (1/6) Operating Systems ü A lot of OSes including Linux, Windows, OS X and so on. (Source: IEEE Spectrum, 2001) (source: http: //nick-os. deviantart. com/art /Os-war-choose-your-poison-110510677) 3
Linux Introduction (2/6) Linux Definition ü ü Linux is a clone of the UNIX Operating System Written from scratch by Linus B. Torvalds, with assistance from a loosely-knit team of hackers across the Network ü ü ü Univ. of Helsinki in Finland May, 1991: Release 0. 0. 1 version 6. September, 2016: Release 4. 7. 2 (refer to www. kernel. org) 4
Linux Introduction (3/6) Unix-like OSes (Source: wikipedia. org) POSIX (Portable Operating Systems Interface for UNIX) 5
Linux Introduction (4/6) Ken and Dennis
Linux Introduction (5/6) Contributors ü GNU (www. gnu. org) § Richard M. Stallman (rms) § Free software ü Minix § Andrew Tanenbaum ü BSD § Linus Torvalds has said that if 386 BSD had been available at the time, he probably would not have created Linux
Linux Introduction (6/6) Applications (Source: images at google)
How to access Linux (1/4) Standalone (usually with multi-boot) Virtualization Client-Server ü In our course § Client: terminal emulator (telnet client, putty, …) § Server: Linux system (PC) • IP: 220. 149. 236. 2 (primary), 220. 149. 236. 4 (secondary) 9
How to access Linux (2/4) Client ü ü telnet, ssh, ping, … putty, Secure. CRT, mlterm, … 10
How to access Linux (3/4) Putty with ssh ü ü ü IP: 220. 149. 236. 2 (check that “type is ssh” and “port is 22”) Colours: click “Use system colours Translation: choose “UTF-8” 11
How to access Linux (4/4) Login and shell ü ü ID: sys 123456 (the last 6 numbers of Student ID) Default passwd: ***** (change using the “passwd” command) 12
How to use commands in Linux (1/7) UNIX ü Two key objects in UNIX: file as a “place” and process (task) as a “life” (by M. Bach, The Design of the UNIX Operating Systems) File ü ü ü Data set or stream of bytes (attributes: start, size, current offset) Associated with disk blocks Supports a variety of objects using file concept (eg. device, network, memory, and even process) Task (process) ü ü ü Program in execution Associated with CPUs (Scheduling entity) Having context such as memory space and CPU registers 13
How to use commands in Linux (2/7) file related command ü create § vi, gcc, mknod, … ü copy/move § cp, mv, ln, … ü delete § rm ü listing § ls ü file content view § more, cat, head, tail, objdump, hexdump ü file attributes manipulation § chmod, chown, chgrp, touch ü redirection § > 14
How to use commands in Linux (3/7) directory ü ü a set of files provide hierarchical structure of files home directory, root directory, current directory relative path, absolute path directory related command ü create § mkdir ü change § cd ü delete § rmdir ü current position § pwd 15
How to use commands in Linux (4/7) file attribute manipulation ü Permission and owner 16
How to use commands in Linux (5/7) vi editor (vim) ü ü ü ü 3 states § input/command/line command At first: command state Switch to the input state § a (append), i (insert), o, r, … Switch to the command state § ESC Switch to the line command state § : at command state Actions allowed at the command state § Cursor movement: {h, j, k, l}, arrow § Page movement: Ctrl+{F, B, D, U} § Deletion: x, dw, dd, u, … Actions allowed at the line command state § : wq, : w, : q!, r <filename>, : s, set, … 17
How to use commands in Linux (6/7) task related commands ü ü task status § ps, pstree, top, /proc Creation and deletion § Using shell (fork() and execve(), internally) § kill 18
How to use commands in Linux (7/7) Generalization of file concept ü Treat device, socket, IPC as a file
Compilation in Linux (1/6) Overall (Source: computer systems: a programmer perspective, Figure 1. 3) 20
Compilation in Linux (2/6) Assembly code opcode, operand (register, memory, immediate, . . . ) Can be different based on the 21 version of kernel and compiler
Compilation in Linux (3/6) Relocatable code 22
Compilation in Linux (4/6) Executable code 23
Compilation in Linux (5/6) What are the execution results of this program? 24
Compilation in Linux (6/6) debugger There are various valuable debugger commands such as breakpoint, step, info reg, … 25
Summary Discuss about the features of Linux Understand the commands related to file and process Explore the language hierarchy in Linux (UNIX) Homework 2. 1. 1 Make a file using vi editor that contains your favorite poem 1. 2 Make a snapshot that - has at least 10 commands. - shows student’s ID and date (using whoami and date) - also includes the compilation practice (eg. gcc, as, gdb) - Server IP: 220. 149. 236. 2 or 220. 149. 236. 4 26
Homework 2. Snapshot Example 27
- Slides: 27