Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

Similar documents
CSE 351. Introduction & Course Tools

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Intermediate Programming, Spring Misha Kazhdan

Laboratory 1 Semester 1 11/12

Lab 1 Introduction to UNIX and C

Lab 1 Introduction to UNIX and C

EL2310 Scientific Programming

EL2310 Scientific Programming

CSC111 Computer Science II

Projects and Environment Introduction

PRINCIPLES OF OPERATING SYSTEMS

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Introduction to Linux

COMP s1 Lecture 1

Spring Modern Computer Science in a Unix Like Environment CIS c

Operating System Labs. Yuanbin Wu

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

Introduction to Linux

Introduc+on. General Information. General Information. General Information. General Information. General Information

CMPT 300. Operating Systems. Brief Intro to UNIX and C

System Programming. Introduction to Unix

Introduction to Supercomputing

Problem Set 1: Unix Commands 1

Exercise 1: Basic Tools

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

Linux at the Command Line Don Johnson of BU IS&T

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

Hand-on Labs for Chapter 1 and Appendix A CSCE 212 Introduction to Computer Architecture, Spring

Introduction to Linux. Fundamentals of Computer Science

Working with Shell Scripting. Daniel Balagué

Practical Computing-II. Programming in the Linux Environment. 0. An Introduction. B.W.Gore. March 20, 2015

Lecture 01: welcome and intro what LSD and Unix have in common

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

Temple University Computer Science Programming Under the Linux Operating System January 2017

CS356: Discussion #1 Development Environment. Marco Paolieri

CS CS Tutorial 2 2 Winter 2018

CS 253: Intro to Systems Programming 1/21

Programming and Data Structure Laboratory (CS13002)

15213 Recitation Section C

CSE 303 Lecture 8. Intro to C programming

1. The Mac Environment in Sierra Hall 1242

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

CS 261 Recitation 1 Compiling C on UNIX

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Getting started with UNIX/Linux for G51PRG and G51CSA

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

Introduction to Linux

Perl and R Scripting for Biologists

1. The Mac Environment in SIE 1222

CS108 Software Systems: UNIX. Fall 2011

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Compiling C/C++ programs

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Practical Session 0 Introduction to Linux

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

Introduction: The Unix shell and C programming

Physics 306 Computing Lab 1: Hello, World!

Introduction to Linux Overview and Some History

Version Control with Git

CSCE 212H, Spring 2008, Matthews Lab Assignment 1: Representation of Integers Assigned: January 17 Due: January 22

Course Wiki. Today s Topics. Web Resources. Amazon EC2. Linux. Apache PHP. Workflow and Tools. Extensible Networking Platform 1

CSE 303: Concepts and Tools for Software Development

Dalhousie University CSCI 2132 Software Development Winter 2018 Lab 8, March 22

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

Operating System Labs. Yuanbin Wu

Parallel Programming Pre-Assignment. Setting up the Software Environment

Sep 12, 2006 Lecture 2: System Programming

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

last time in cs recitations. computer commands. today s topics.

CS11001/CS11002 Programming and Data Structures Autumn/Spring Semesters. Introduction

Summary of Last Class. Processes. C vs. Java. C vs. Java (cont.) C vs. Java (cont.) Tevfik Ko!ar. CSC Systems Programming Fall 2008

ECE 2036 Lab 1: Introduction to Software Objects

23. Check that hello.txt now contains (substitute your info for mine): hello rcwhaley: Dr. Whaley

Unix and C Program Development SEEM

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

EE516: Embedded Software Project 1. Setting Up Environment for Projects

EC 413 Computer Organization

Overview of Unix / Linux operating systems

C++ Programming on Linux

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

CSC231 C Tutorial Fall 2018 Introduction to C

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

In case you didn t get it (or you were too lazy to check)

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

ECE 471 Embedded Systems Lecture 4

EKT332 COMPUTER NETWORK

Basic C Program: Print to stdout. Basic C Program. Basic C Program: Print to stdout. Header Files. Read argument and print. Read argument and print

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

Introduction to Linux

Intro to Linux & Command Line

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

CMPUT 201: Practical Programming Methodology. Guohui Lin Department of Computing Science University of Alberta September 2018

Programming refresher and intro to C programming

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

EECS 211 Lab 2. Getting Started. Getting the code. Windows. Mac/Linux

Transcription:

Intro to Linux and C CSCI 2400/ ECE 3217: Computer Architecture Instructors: David Ferry 1

Overview Linux C Hello program in C Compiling 2

History of Linux Way back in the day: Bell Labs Unix Widely available to students and instructors Very machine-independent Some direct Unix branches (e.g. Berkeley Unix or BSD) Others were inspired by Unix Minix- by Andrew S. Tannenbaum, an educational micro kernel Could re-implement the high-level design of Unix (e.g. Minix was originally system-call compatible with Unix) Linus Torvalds saw Minix and wanted to do his own version Wrote basic kernel from scratch Borrowed good ideas from Minix Included early support for GNU project software Completely free OS and system software 3

Linux Today Very small usage in desktop/laptop market (~3% in US) Android is the biggest OS in mobile computing (~53% of US) Up to 85% of devices worldwide Linux drives internet servers (~97% of public servers) Linux drives supercomputing (~99% of TOP500 computers) 4

Getting Started with Linux at SLU Linux classroom and Linux lab on 1 st floor Ritter Department Linux server: hopper.slu.edu Should use same username as SLU, but different password Talk to Dennis about password issues (office adjacent to lab) Recommended: Login to hopper.slu.edu via ssh Suggested: Work on local machine in lab Suggested: Login to hopper.slu.edu via NoMachine You may work however you like, but I can t support other methods (e.g. Linux in a virtual machine on your laptop) 5

Logging in via SSH From OSX can use terminal directly Can transfer files with scp command From Windows can use an ssh client My favorite: Secure Shell extension for Chrome browser Plenty of others, just search for them Transfer files via WinSCP Username: your SLU username Hostname: hopper.slu.edu Via terminal: ssh dferry@hopper.slu.edu 6

Using the command line Enter one command per line Lots of programs to accomplish what you want to do Just search How do I accomplish XYZ in Linux terminal? Useful commands: Command ls ls -l cd mkdir rm rm -r cp file1 file2 cat file wget url Description Lists contents of current directory Lists contents in list format Change current directory Make a new directory Remove a file Remove a directory Copies file1 to file2 Prints file to the terminal Downloads url to the current directory 7

Editing Text Files Text files- very important! C programs for this class Very efficient storage for data and configuration Classic editors: vi and emacs Hard to get started initially Way faster once you get the hang of it Designed for low-bandwidth, spotty connections (think phone modems) Definitely worth it Other editors: Text editors- search them! GUI editors- search them! 8

For next time: Find a good Linux environment you d like to use Try logging into hopper.slu.edu Next homework involves writing C code 9

Overview Linux C Hello program in C Compiling 10

The C Language Developed at Bell Labs to write Unix Practical language for practical projects Most OSes are written mostly in C (some assembly code) Most system libraries and tools are written entirely in C Small, simple language Easy to learn (especially at the time) Easy to port to different platforms Designed to replace Assembly Language Provides low-level access to memory Most operations map closely to assembly language operations Strongly typed, static type checking int, unsigned, float, double, char, etc. No runtime protection 11

Type Checking in C Several primitive types: int, unsigned, float, double, char, etc. The compiler will not warn about possibly unsafe operations: int a; unsigned b; b = a; Correctness is up to the programmer! This kind of stuff is usually a bad idea though 12

Command Line Input in C The main() function has two arguments: argc is the number of arguments argv is a vector of strings that hold those arguments E.g.: printing all values as strings int main ( int argc, char* argv[] ){ } for( i = 0; i < argc; i++ ){ } printf( %s\n, argv[i]); 13

Converting Strings to Numbers How to convert 42 into the numeric value 42? atoi() Fast, easy, but dirty No safety or type checking Undefined behavior on overflow scanf() Works with floats and other data types Undefined behavior on overflow strtol() Robust error checking, industrial grade 14

Manual Pages! (A.K.A. man pages) All of C (and much more beside) is documented in the manual pages, use them! At the command prompt: man man manual for the manual pages() man atoi manual for the function atoi() man scanf manual page for the function scanf() Sometimes there are collisions: man printf manual page for the bash command printf man 3 printf manual page for the C function printf() man man shows man page sections 15

C Operators Usual arithmetic operators: +, -, *, %, /, = Bitwise operators: & - AND - OR ^ - XOR ~ - complement << - left shift >> - right shift Ternary operator: (cond)? (exec if true ) : (exec if false) Logical Operators: && - logical AND - logical OR! - logical NOT Relational Operators == - True if equal!= - True if not equal < - True if less than > - True if greater than <= - True if less or equal >= - True if greater or equal 16

Hello, world! in C #include <stdio.h> int main( int argc, char* argv[] ){ int var = 42; printf( Hello, world!\n ); printf( Value of var: %d\n, var); } return 0; 17

Compiling C programs We will use the gcc compiler If you have a program named prog.c: gcc -Wall -o prog prog.c -Wall turns on all warnings -o <name> output file name (default is a.out) Program files are listed by themselves Order isn t important 18