COSC350 System Software

Similar documents
Preview. Story about Linux. Story about Linux. Story about Linux. Story about GNU/Linux. Story about GNU/LINUX 1/26/2018

Review. Preview. Linux System Roadmap (Libraries)

Linux system programming - About this course

Getting Started. An Introduction to UNIX, Linux, and GNU

Lecture 1. Course webpage. Syllabus and schedule, textbooks CS Lab, Virtual Box. Handouts, assignments Supplemental resources

Errors During Compilation and Execution Background Information

Unix to Linux. CS 3113 Fall 2018 Dr. Christan Grant

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

EL2310 Scientific Programming

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

Overview of Unix / Linux operating systems

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

EL2310 Scientific Programming

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

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Your first C and C++ programs

C: Program Structure. Department of Computer Science College of Engineering Boise State University. September 11, /13

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Introduction to Linux

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

C and C++ I. Spring 2014 Carola Wenk

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Introduction to Linux

Chapter 1 INTRODUCTION

CS240: Programming in C

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

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c

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

Introduction to Linux Overview and Some History

Topic 6: A Quick Intro To C

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Chapter 1 Introduction to Computers and C++ Programming

The Compilation Process

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009

PROGRAMMAZIONE I A.A. 2017/2018

Introduction to Linux

CS2141 Software Development using C/C++ Compiling a C++ Program

Laboratorio di Programmazione. Prof. Marco Bertini

Baby Steps: Some Simple Programs in C, C++, and Java

Presented By : Gaurav Juneja

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

by Pearson Education, Inc. All Rights Reserved.

COMP322 - Introduction to C++

Laboratorio di Tecnologie dell'informazione

CS108 Software Systems: UNIX. Fall 2011

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

EC 413 Computer Organization

CSCI 2132 Software Development. Lecture 8: Introduction to C

2 Compiling a C program

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Have examined process Creating program Have developed program Written in C Source code

C Language, Token, Keywords, Constant, variable

Obtained the source code to gcc, one can just follow the instructions given in the INSTALL file for GCC.

KYC - Know your compiler. Introduction to GCC

Operating System Labs. Yuanbin Wu

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

CSC209 Fall Karen Reid 1

EECS2031 Software Tools

Why VC++ instead of Dev C++?

UNIX Makefile. C Project Library Distribution and Installation.

Introduction to Supercomputing


The C language. Introductory course #1

This tutorial covers a foundational understanding of IPC. Each of the chapters contain related topics with simple and useful examples.

Linux Operating System

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

Introduction Presentation A

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012

CSE 124 Discussion (10/3) C/C++ Basics

CIS 90 Introduction to UNIX/Linux

COURSE OUTLINE. UNIX Programming 2014 Fall by Euiseong Seo

Operating Systems Lab

Threads. Threads (continued)

COMP1917: Computing 1 1. Introduction

CSCI 2132 Final Exam Solutions

Introduction of Linux. Huang Cheng-Chao Dept. of Comput. Sci. & Tech. East China Normal University

Introduction to Programming

Embedded Systems Programming

COMP26912: Algorithms and Imperative Programming

Chapter 7: Preprocessing Directives

Introduction: The Unix shell and C programming

CSI33 Data Structures

Introduction to Linux

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

COMP s1 Lecture 1

EL2310 Scientific Programming

Assignment 1. CSI Programming Practice, Fall 2011

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory

Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang

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

EE458 - Embedded Systems Lecture 4 Embedded Devel.

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

Tutorial-2a: First steps with C++ programming

Introduction to C An overview of the programming language C, syntax, data types and input/output

The following program computes a Calculus value, the "trapezoidal approximation of

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Kattis Team Guide version 1.1

Transcription:

COSC350 System Software Topics: The UNIX/Linux Operating System Basics UNIX/Linux basic commands, login scripts and environment set up, C programming environment, introduction to basic shell scripts Working with files File and directory structure, low level file access, standard I/O library, formatted input and output. Process Basic concepts of Linux process and process attributes, process control using fork, exec and wait, process relationship. COSC 350 System Software, Fall2015 1

COSC350 System Software Signals Concept of signals, usage of signal between processes, process functions Threads Thread concepts, thread creation, termination, synchronization, thread control, thread attributes Inter-process Communication Basic concepts of inter-process communication using signals and pipes Socket Programming Basic concepts of socket communication, network information and multiple clients COSC 350 System Software, Fall2015 2

Preview What is Linux What is GNU/Linux Project Introduction to C Programming C System Environment C compilers in Linux Linux System Roadmap Header files Libraries Static Libraries Shared Libraries COSC 350 System Software, Fall2015 3

Story about Linux 1985 Professor Andy Tanenbaum ( University of Amsterdam) wrote a Unix like operating system for PCs from scratch, based on System V standards POSIX and IEEE, called MINIX. Linus Torvald ( ) wanted to upgrade MINIX and put in features and improvements, but Andrew Tanenbaum wanted MINIX the way it was and so Linus decided to write his own kernel. He released Linux on the Internet as an Open Source product and under his own license and then later in 1991. COSC 350 System Software, Fall2015 4

Story about Linux The Tanenbaum-Torvalds Debate http://oreilly.com/catalog/opensources/book/appa.html COSC 350 System Software, Fall2015 5

Story about Linux The idea of the penguin came from the creator of Linux, Linus Torvalds. The image was made by a man named Larry Ewing ( )in a competition to create a logo. The image, Tux, did not win, but it was picked as a mascot later. COSC 350 System Software, Fall2015 6

Story about GNU/LINUX The FSF (Free Software Foundation), started by Richard Stallman.( ) The FSF started a project called GNU to fulfill this aim. GNU stands for "GNU is Not Unix" The GNU Project was launched in 1984 to develop a complete Unix-like operating system which is free software: COSC 350 System Software, Fall2015 7

Story about GNU/Linux By 1991 GNU had already amassed a compiler (GCC), a C library, both very critical components of an operating system, and all associated generic Unix base programs but not kernel. The FSF naturally adopted the Linux kernel to complete the GNU system - the GNU/Linux operating system COSC 350 System Software, Fall2015 8

Story about Linux Many operating system platform are developed by using the Linux kernel. (i.e. SUSE, Red Hat, Ubuntu, Android ) The current full-featured version is 3.16.x and development continues. The latest stable version of the Linux kernel is: stable version: 3.16.1 2014-08-14, check http://www.kernel.org COSC 350 System Software, Fall2015 9

Linux Programs Linux applications are represented by two special types of files: Executable file directly executable by a computer. A Script collection of instruction for another program (interpreter) In Linux, we can replace scripts with compiled program (and vice versa). COSC 350 System Software, Fall2015 10

Linux Architecture What is Operating System? The software that controls the hardware resources and provide an programming environment under which programs can run (interface between HW and SW). We call this as kernel. System calls is the layer of software interface to the kernel (unbuffered I/O) Library functions are built on top of system call (Buffered I/O). A shell is a command-line interpreter that read user input and execute command. COSC 350 System Software, Fall2015 11

Linux Architecture Application Software Shell System Calls Kernel Hardware Library Functions COSC 350 System Software, Fall2015 12

Introduction to C Programming C is a general-purpose, block structured, procedural, imperative computer programming language. It is developed in 1972 by Dennis Ritchie ( ) at the Bell Telephone Laboratories for use with the Unix operating system. C has greatly influenced many other popular programming languages, most notably C++, which originally began as an extension to C. COSC 350 System Software, Fall2015 13

C System Environment Source code Object code Text editor Preprocessor Compiler Linker Modified Source code Executable Code COSC 350 System Software, Fall2015 14

The C Compiler in LINUX Linux provide several c compilers c99 POSIX systems cc UNIX Systems gcc GNU How to compile a program with gcc Similar with g++ compiler 1. gcc c file.c 2. gcc file.o o file Or 1. gcc o file file.c Execute a program file./file which means execute the program in the current directory COSC 350 System Software, Fall2015 15

Introduction to C // Shows simple program #include <iostream> using namespace std; int main () { cout << Welcome to C++! \n ; return 0; } /* A simple program with C */ #include <stdio.h> int main () { printf( Welcome to C! \n ); return 0; } COSC 350 System Software, Fall2015 16

Introduction to C // twonum.cpp #include <iostream> using namespace std; int main () { // declaration of variables int a1, a2, sum; cout << "Enter first integer \n"; cin >> a1; cout << "Enter second integer \n"; cin >> a2; sum = a1 + a2; cout << " Sum is " << sum <<endl; return 0; } // twonum.c #include <stdio.h> int main () { /*declaration of variables */ int a1, a2, sum; printf("enter first integer \n"); scanf("%d",&a1); printf ("Enter second integer \n"); scanf("%d", &a2); sum = a1 + a2; printf (" Sum is %d \n", sum); return 0; } COSC 350 System Software, Fall2015 17

(Applications) Applications /usr/bin : applications supported by system for general user /usr/local/bin or /usr/local/opt: applications for specific host computer or local networks, added by system admin. Additional programming system such as X Window may have their own directories such as /usr/x11 gcc compilers are located in /usr/bin or /usr/local/bin COSC 350 System Software, Fall2015 18

(Header files) Header files header files must be included in a C programming. Preprocessor include header library files before compiling. Header files are located in /usr/lib/include or its subdirectories for specific system /usr/lib/include/sys: header files for system /usr/lib/include/linux: header files for Linux /usr/lib/include/x11: header files for X Window /usr/lib/include/g++: header file for g++ compiler COSC 350 System Software, Fall2015 19

(Header files) If a header file in included, preprocessor search the header file in the standard location. We can also include a header file which is located in the non-standard location by passing the location information. EX) >gcc I/usr/openwin/include fred.c Provide information to compiler where included header file is located COSC 350 System Software, Fall2015 20

(Preprocessing) including files #include <stdio.h> int main() { printf("hello, world!\n"); return 0; } The preprocessor replaces the line #include <stdio.h> with the text of the file 'stdio.h', which declares the printf() among other things. 21

(Preprocessing) Conditional compilation #ifdef unix /* unix is usually defined by compilers targeting Unix systems */ # include <unistd.h> #elif defined _WIN32 /* _Win32 is usually defined by compilers targeting 32 or 64 bit Windows systems */ # include <windows.h> #endif gcc o test.exe -D_WIN32 22

(Preprocessing) Macro definition and expansion #define PI 3.14 #define RADTODEG(x) ((x) * 57.29578) x = PI * 2; y = RADTODEG(1.0) * PI; will be translated into x = 3.14 * 2; y = ((1.0) * 57.29578) * 3.14; 23

(Linking) Inserts code (or maps in shared libraries) to resolve program library references, and/or combines object modules into an executable image suitable for loading into memory. Subprogram Compiled Address P 0-999 0-999 Executable Address Q 0-1999 1000 2999 Library 0-4999 3000 7999 24

(Linking - windows) Static linking is the result of the linker copying all library routines used in the program into the executable image. This may require more disk space and memory than dynamic linking, but is both faster and more portable, since it does not require the presence of the library on the system where it is run. Dynamic linking is accomplished by placing the name of a sharable library in the executable image. Actual linking with the library routines does not occur until the image is run, when both the executable and the library are placed in memory. An advantage of dynamic linking is that multiple programs can share a single copy of the library. 25

(Libraries) Libraries are collection of precompiled functions. Standard libraries locations: /lib and /usr/lib A library filename starts with lib, then follows the part indicating what library is (m for math library, c for the C library) Two Types of libraries.a : static library.so : shared library COSC 350 System Software, Fall2015 26

(Libraries) Linker knows the standard libraries locations. We can also instruct the linker to search a library at a specific location by passing the name of library with full path. gcc o some some.c /usr/lib/libm.a Shorted standard library location lm means use libm.a static library gcc o some some.c -lm COSC 350 System Software, Fall2015 27

(Libraries) We can also direct special directory by using L flag where specific library is located. gcc -o some -L/usr/openwin/lib some.c laa : means compile some.c with library libaa.o which is located in /usr/openwin/lib directory COSC 350 System Software, Fall2015 28

(Static Libraries) Static Library (call Archives) collection of object files in a ready to use form. To use a function in a Library, need include header file in your program. We can create and maintain our own static libraries by using ar (archive) program and compiling functions separately with gcc c. COSC 350 System Software, Fall2015 29

(How to Make Static Libraries) How to make your own static libraries? 1. Make files for reusable functions. 2. Create object codes by using commend gcc c file1.c (create file1.o) gcc c file2.c (create file2.o) gcc c file3.c (create file3.o) 3. Create a header file (foo.h) which contains function prototypes for reusable functions. This header file must be included in the program where the reusable function is used. 4. Create a library by using ar commend COSC 350 System Software, Fall2015 30

(How to Make Static Libraries) /* bill.c */ #include <stdio.h> void bill (char *arg) { printf("bill: You passed %s\n, arg); } /* A header file some.h for two function prototype */ void bill (char *); void fred (int); /*fred.c */ #include <stdio.h> void fred (int arg) { printf("fred! You are passed: %d\n", arg); } COSC 350 System Software, Fall2015 31

(How to Make Static Libraries) /* program.c which include main function*/ #include " some.h" int main () { bill( Hello world ); fred (100); return 0; } COSC 350 System Software, Fall2015 32

(How to Make Static Libraries) gcc -c bill.c bill.o Create objects gcc -c fred.c fred.o ar crv libbf.a bill.o fred.o libbf.a Create a library with two objects c: create r: replace v:verbose gcc o program program.o libbf.a Assume libbf.a is located in the currently working directory Create a executable code named program with library libbf.o COSC 350 System Software, Fall2015 33

(How to Make Static Libraries) gcc -c bill.c bill.o Create objects gcc -c fred.c fred.o ar crv libbf.a bill.o fred.o libbf.a Create a library with two objects gcc o program /home/separk/cosc350/bin program.o libbf.a Assume the library libbf.a is located in /home/separk/cosc350/bin Create a executable code named program with library libbf.o COSC 350 System Software, Fall2015 34

(Shared Libraries) Shared Libraries Shared libraries are stored in the same location as static libraries, but named with.so. There is always only one copy of library in memory. A shared library is shared by different programs (processes) can save memory space. COSC 350 System Software, Fall2015 35