System Programming Chapter 2 Programming Environment September 10
System Programming Chapter 2. Programming Environment September 10, 2013 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 7 (or 8), OS X, … (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 8. September, 2013: Release 3. 10. 11 (refer to www. kernel. org) 4
Linux Introduction (3/6) Unix-like OSes (Source: wikipedia. org) F POSIX (Portable Operating 5 Systems Interface for UNIX)
Linux Introduction (4/6) Ken and Dennis
Linux Introduction (5/6) Contributors ü GNU (www. gnu. org) § Richard Stallman § 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 ü ü ü 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 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) 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, … 16
How to use commands in Linux (5/7) file attribute manipulation ü Permission and owner 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 19
Compilation in Linux (1/6) Overall hello. c Source program (text) printf. o Preprocessor (cpp) hello. i Modified source program (text) Compiler (cc 1) hello. s Assembly program (text) Assembler hello. o (as) Linker (ld) Relocatable object programs (binary) hello. out Executable object program (binary) (Source: computer systems: a programmer perspective, Figure 1. 3) 20 other binary name instead of “a. out” F $ “gcc –o test. out test. c” if you want to use
Compilation in Linux (2/6) Assembly code opcode, operand (register, memory, immediate, . . . ) F May 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 F 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) F Homework 1. 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) - Server IP: 220. 149. 236. 2 or 220. 149. 236. 4 26
Homework 1. Snapshot Example 27
- Slides: 27