CSC322 C Programming and UNIX Stephan Schulz

Total Page:16

File Type:pdf, Size:1020Kb

CSC322 C Programming and UNIX Stephan Schulz CSC322 C Programming and UNIX Stephan Schulz Department of Computer Science University of Miami [email protected] http://www.cs.miami.edu/~schulz/CSC322.html Prerequisites: CSC220 or EEN218 Hackers! Hacker [originally, someone who makes furniture with an axe] 1. A person who enjoys exploring the details of programmable systems and how to stretch their capabilities, as opposed to most users, who prefer to learn only the minimum necessary. 2. One who programs enthusiastically (even obsessively) or who enjoys programming rather than just theorizing about programming. 3. A person capable of appreciating hack value. 4. A person who is good at programming quickly. 5. An expert at a particular program, or one who frequently does work using it or on it; as in ‘a Unix hacker’. (Definitions 1 through 5 are correlated, and people who fit them congregate.) 6. An expert or enthusiast of any kind. One might be an astronomy hacker, for example. 7. One who enjoys the intellectual challenge of creatively overcoming or circumventing limitations. 8. [deprecated] A malicious meddler who tries to discover sensitive information by poking around. Hence ‘password hacker’, ‘network hacker’. The correct term for this sense is cracker. The New Hacker’s Dictionary (aka the Jargon File) Stephan Schulz 2 UNIX and You The UNIX Operating System Stephan Schulz 3 UNIX and You The UNIX Operating System Stephan Schulz 4 UNIX and You The UNIX Operating System C Stephan Schulz 5 Our AIM / etc home usr dev bin joe jackjill ls man cat hdaThe mouse mta I n UNIX t e PID: PID: r Operating System n 182 512 e t C Stephan Schulz 6 The Myth UNIX is a big-iron operating system UNIX is complicated UNIX is hard to use UNIX has been created by SUN, IBM, HP, and other large companies UNIX is monolithic Stephan Schulz 7 Counterpoint UNIX was developed on small machines and became popular on the “killer micros”. UNIX dialects now run on everything from a PDA to CRAY supercom- puters UNIX is based on simple and elegant principles (but has added a some cruft over the years) UNIX is not particularly hard to use (compared to the power it gives to the user), but has a reasonably steep learning curve. It’s not a “show-me” operating system, but a “tell me” operating system, UNIX has been created in a research environment, and much of it has been developed in informal settings by hackers. Much of the impetus for UNIX comes from free versions (Linux, Net-, Open-, FreeBSD), although many companies contribute to it’s development Many UNIX kernels are monolithic, but the UNIX system is extremly modular. Stephan Schulz 8 UNIX First portable operating system (NetBSD: 18 processor architecures, ≈ 50 com- puter architecures) Written in a “high-level” language (C) Small (for what it does): – Recent LINUX kernel: 2.4 million LOC (1.4 million for driver, 0.4 million architecture-dependent stuff (16 ports) – Windows 2000: Estimates range from 29 million to 65 million LOC, supports just 1.5 architecures Modular (though often on a monolithic kernel) – Separate windowing system (X) and window managers – Various Desktop-Solutions (CDE, KDE, Gnome) – Toolbox-philosphy: Combine (lot’s of) simple tools – Underneath: Strong and simple abstraction (“Everything is a file”) Stephan Schulz 9 C “Pragmatic” high level language: – Handles characters, numbers, adresses as implemented by most computers – Small core language, much functionality provided by libraries (mostly in C!) – Compilers are easy to write – Compilers are easy to port – Even naive compilers produce reasonably efficent code Hacker-friendly – Straightforward compilation (nothing is hidden) – Compact source code (fewer keystrokes, fast to read) – Typed, but no bondage-and-discipline language Adequate support for building abstractions – Structures (composing objects), unions, enumerations – Arrays and pointer – Support for defining new types Stephan Schulz 10 UNIX history tree (simplified) For a fuller tree see http://www.levenez.com/unix/ Stephan Schulz 11 A Short History of UNIX and C 1969 Ken Thompson wrote the first UNIX (in assembler) on a PDP7 at AT&T Bell Labs, allegedly to play Space Travel 1970 Brian Kernighan coins the name UNIX. The UNIX project gets a PDP11 and a task: Writing a text processing system 1971-72 Creation of C (Dennis Ritchie), UNIX rewritten in C 1972 Pipes arrive, UNIX installed on 10 (!) systems 1975 AT&T UNIX “Version 6” distributed with sources under academic licenses 1976 Ken Thompson in Berkely, leading to BSD UNIX 1977 1BSD release 1978 UNIX “Version 7”, leading to System V (AT&T) Stephan Schulz 12 A Short History of UNIX and C 1978 3BSD, adding virtual memory 1980 Microsoft XENIX brand of UNIX 1982 4.2BSD, adding TCP/IP 1982 SGI IRIX 1983 Bjarne Stroustrup creates C++ (at AT&T Bell labs) 1983 GNU Project announced (Aim: Free UNIX-like system) 1983-1984 Berkeley Internet Name Demon (BIND) created 1984 SUN introduces NFS (Network File System) 1985 Free Software Foundation (Stallman), GNU manifesto, GNU Emacs Stephan Schulz 13 A Short History of UNIX and C 1986 HP-UX, SunOS3.2 (from BSD Unix), “attack of the killer micros” 1986 MIT Project Athena creates X11 (Network window system) 1986 POSIX.1 (Portable operating system interface standard) 1988 GNU GPL 1988 System VR4 “One UNIX to rule them all” (AT&T+SUN) 1988 NeXTCUBE with NeXTSTEP operating system 1989 ANSI-C Standard “C89”(adds prototypes, standard library) 1889 SunOS 4.0x 1990 Net/1 Release (free BSD UNIX) 1990 IBM AIX Stephan Schulz 14 A Short History of UNIX and C 1991 Linux 0.01, “attack of the killer PCs” (continuing till this day) 1991 World Wide Web born 1991–1992 Lawsuits around BSD UNIX Net/1 and Net/2 releases 1992 SunOS 5 aka Solaris-2 (from System VR4) 1993 FreeBSD 1.0 1994 Linux 1.0 1994 NetBSD 1.0, 4.4BSD Lite (unencumbered by AT&T copyrights, becomes new base for all non-commercial BSD flavours) 1995 “UNIX wars” are over 1996 Tux the Penguin becomes Linux mascot Stephan Schulz 15 A Short History of UNIX and C 1998 UNIX-98 branding (Single UNIX specification) 2000 New ANSI “C99” 2001 IBM runs prime time TV ads for Linux 2001 UNIX-based MacOS X 2002 Linux is at version 2.4, Emacs is version 21.2, SunOS is at 5.9 (aka Solaris 9), BIND is version 9.2.1 Stephan Schulz 16 Another Opinion UNIX is not an operating system. but is the collected folklore of the hacker community! Stephan Schulz 17 Spot the Even Ones Stephan Schulz 18 Upshot You don’t have to grow a beard to become a world-class UNIX hacker. but it does seem to help! Stephan Schulz 19 CSC322 C Programming and UNIX UNIX from a User’s Perspective Stephan Schulz Department of Computer Science University of Miami [email protected] http://www.cs.miami.edu/~schulz/CSC322.html UNIX Architecture Application Shell Libraries UNIX Kernel Hardware Stephan Schulz 21 UNIX Architecture Application Shell Libraries UNIX Kernel Hardware Stephan Schulz 22 Some Concepts UNIX is a multi-user system. Each user has: – User name (mine is schulz on most machines) – Numerical user id (e.g. 500) – Home directory: A place where (most of) his or her files are stored UNIX is a multi-tasking system, i.e. it can run multiple programs at once. A running program (with its data) is called a process. Each process has: – Owner (a user) – Working directory (a place in the file system) – Various resources A shell is a command interpreter, i.e. a process accepting and executing commands from a user. – A shell is typically owned by the user using it – The initial working directory of a shell is typically the users home directory (but can be changed by commands) Stephan Schulz 23 More on Users There are two kinds of users: – Normal users – Super users (“root”) Super-users: – Have unlimited access to all files and resources – Always have numerical user id 0 – Normally have user name “root” (but there can be more than one user name associated with UID 0) – Can seriously damage the system! Normal users – Can only access files if they have the appropriate permissions – Can belong to one or more groups. Users within a group can share files – Usually cannot damage the system or other users files! Stephan Schulz 24 The User Interface UNIX: Provide Tools, Not Policy – Most tools operate on all (ASCII) file formats – Extremely configurable environment – different users have different user expe- riences – No restrictions ⇔ Little consistency – We will assume the default environment on the lab machines for examples X Window System: Provide Mechanisms, Not Policy – Windowing system offers (networked) drawing primitives – Different GUIs built on top of this – GUI conventions may even differ from one application to the other! – Modern desktop environments (GNOME/KDE) try to change this, but you are bound to use many legacy applications anyways! Stephan Schulz 25 My Graphical Desktop Stephan Schulz 26 Default KDE Desktop (SuSE Linux) Stephan Schulz 27 Desktop Discussion My Desktop – Uses windowing mostly to provide a better text-based interface (compared to pure text terminals) – Text editor and shell (command line) windows – (Can also run graphical applications) KDE Desktop – Graphical, mouse-based user experience – Mostly a launcher for GUI-based programs ∗ Office prgrams ∗ Graphics programs ∗ Web browser – Can also run shell windows! Stephan Schulz 28 KDE Desktop with Terminal Application Stephan Schulz 29 Exploring the Text Interface Convention: System output is shown in typewriter font, user input is written in bold face, and comments (not to be entered) are written in italics. whoami will print the user name of the current user (more exactly: It will print the first user name associated with the effective user id) [schulz@gettysburg ∼]$ whoami schulz pwd prints the current working directory (more later): [schulz@gettysburg ∼]$ pwd /lee/home/graph/schulz Non-standard setup! ls lists the files in the current working directory: [schulz@gettysburg ∼]$ ls core Desktop Not much there at the moment Stephan Schulz 30 Text Interface Example (contd.) Most UNIX programs accept options to modify they behavior.
Recommended publications
  • University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science
    University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science EECS 61C, Fall 2003 Lab 2: Strings and pointers; the GDB debugger PRELIMINARY VERSION Goals To learn to use the gdb debugger to debug string and pointer programs in C. Reading Sections 5.1-5.5, in K&R GDB Reference Card (linked to class page under “resources.”) Optional: Complete GDB documentation (http://www.gnu.org/manual/gdb-5.1.1/gdb.html) Note: GDB currently only works on the following machines: • torus.cs.berkeley.edu • rhombus.cs.berkeley.edu • pentagon.cs.berkeley.edu Please ssh into one of these machines before starting the lab. Basic tasks in GDB There are two ways to start the debugger: 1. In EMACS, type M-x gdb, then type gdb <filename> 2. Run gdb <filename> from the command line The following are fundamental operations in gdb. Please make sure you know the gdb commands for the following operations before you proceed. 1. How do you run a program in gdb? 2. How do you pass arguments to a program when using gdb? 3. How do you set a breakpoint in a program? 4. How do you set a breakpoint which which only occurs when a set of conditions is true (eg when certain variables are a certain value)? 5. How do you execute the next line of C code in the program after a break? 1 6. If the next line is a function call, you'll execute the call in one step. How do you execute the C code, line by line, inside the function call? 7.
    [Show full text]
  • DC Console Using DC Console Application Design Software
    DC Console Using DC Console Application Design Software DC Console is easy-to-use, application design software developed specifically to work in conjunction with AML’s DC Suite. Create. Distribute. Collect. Every LDX10 handheld computer comes with DC Suite, which includes seven (7) pre-developed applications for common data collection tasks. Now LDX10 users can use DC Console to modify these applications, or create their own from scratch. AML 800.648.4452 Made in USA www.amltd.com Introduction This document briefly covers how to use DC Console and the features and settings. Be sure to read this document in its entirety before attempting to use AML’s DC Console with a DC Suite compatible device. What is the difference between an “App” and a “Suite”? “Apps” are single applications running on the device used to collect and store data. In most cases, multiple apps would be utilized to handle various operations. For example, the ‘Item_Quantity’ app is one of the most widely used apps and the most direct means to take a basic inventory count, it produces a data file showing what items are in stock, the relative quantities, and requires minimal input from the mobile worker(s). Other operations will require additional input, for example, if you also need to know the specific location for each item in inventory, the ‘Item_Lot_Quantity’ app would be a better fit. Apps can be used in a variety of ways and provide the LDX10 the flexibility to handle virtually any data collection operation. “Suite” files are simply collections of individual apps. Suite files allow you to easily manage and edit multiple apps from within a single ‘store-house’ file and provide an effortless means for device deployment.
    [Show full text]
  • Process and Memory Management Commands
    Process and Memory Management Commands This chapter describes the Cisco IOS XR software commands used to manage processes and memory. For more information about using the process and memory management commands to perform troubleshooting tasks, see Cisco ASR 9000 Series Aggregation Services Router Getting Started Guide. • clear context, on page 2 • dumpcore, on page 3 • exception coresize, on page 6 • exception filepath, on page 8 • exception pakmem, on page 12 • exception sparse, on page 14 • exception sprsize, on page 16 • follow, on page 18 • monitor threads, on page 25 • process, on page 29 • process core, on page 32 • process mandatory, on page 34 • show context, on page 36 • show dll, on page 39 • show exception, on page 42 • show memory, on page 44 • show memory compare, on page 47 • show memory heap, on page 50 • show processes, on page 54 Process and Memory Management Commands 1 Process and Memory Management Commands clear context clear context To clear core dump context information, use the clear context command in the appropriate mode. clear context location {node-id | all} Syntax Description location{node-id | all} (Optional) Clears core dump context information for a specified node. The node-id argument is expressed in the rack/slot/module notation. Use the all keyword to indicate all nodes. Command Default No default behavior or values Command Modes Administration EXEC EXEC mode Command History Release Modification Release 3.7.2 This command was introduced. Release 3.9.0 No modification. Usage Guidelines To use this command, you must be in a user group associated with a task group that includes appropriate task IDs.
    [Show full text]
  • M32R Debugger and Trace
    M32R Debugger and Trace TRACE32 Online Help TRACE32 Directory TRACE32 Index TRACE32 Documents ...................................................................................................................... ICD In-Circuit Debugger ................................................................................................................ Processor Architecture Manuals .............................................................................................. M32R ......................................................................................................................................... M32R Debugger and Trace .................................................................................................. 1 Introduction ....................................................................................................................... 4 Brief Overview of Documents for New Users 4 Warning .............................................................................................................................. 5 Quick Start ......................................................................................................................... 6 Troubleshooting ................................................................................................................ 9 SYStem.Up Errors 9 Memory Access Errors 9 FAQ ..................................................................................................................................... 9 CPU specific SYStem Settings and Restrictions ..........................................................
    [Show full text]
  • How to Dump and Load
    How To Dump And Load Sometimes it becomes necessary to reorganize the data in your database (for example, to move data from type i data areas to type ii data areas so you can take advantage of the latest features)or to move parts of it from one database to another. The process for doping this can be quite simple or quite complex, depending on your environment, the size of your database, what features you are using, and how much time you have. Will you remember to recreate the accounts for SQL users? To resotre theie privileges? Will your loaded database be using the proper character set and collations? What about JTA? Replication? etc. We will show you how to do all the other things you need to do in addition to just dumping and loading the data in your tables. 1 How To Dump and Load gus bjorklund head groundskeeper, parmington foundation 2 What do we mean by dumping and loading? • Extract all the data from a database (or storage area) • Insert the data into a new database (or storage area) • Could be entire database or part 3 Why do we dump and load? 4 Why do we dump & load? • To migrate between platforms • To upgrade OpenEdge to new version • To repair corruption • To “improve performance” • To change storage area configuration • To defragment or improve “scatter” • To fix a “long rm chain” problem • Because it is October 5 Ways to dump and load • Dictionary • 4GL BUFFER-COPY • Binary • Replication triggers (or CDC) • Table partitioning / 4GL • Incremental by storage area 6 Binary Dump & Load • binary dump files – not "human readable"
    [Show full text]
  • Process Management
    Princeton University Computer Science 217: Introduction to Programming Systems Process Management 1 Goals of this Lecture Help you learn about: • Creating new processes • Waiting for processes to terminate • Executing new programs • Shell structure Why? • Creating new processes and executing new programs are fundamental tasks of many utilities and end-user applications • Assignment 7… 2 System-Level Functions As noted in the Exceptions and Processes lecture… Linux system-level functions for process management Function Description exit() Terminate the process fork() Create a child process wait() Wait for child process termination execvp() Execute a program in current process getpid() Return the process id of the current process 3 Agenda Creating new processes Waiting for processes to terminate Executing new programs Shell structure 4 Why Create New Processes? Why create a new process? • Scenario 1: Program wants to run an additional instance of itself • E.g., web server receives request; creates additional instance of itself to handle the request; original instance continues listening for requests • Scenario 2: Program wants to run a different program • E.g., shell receives a command; creates an additional instance of itself; additional instance overwrites itself with requested program to handle command; original instance continues listening for commands How to create a new process? • A “parent” process forks a “child” process • (Optionally) child process overwrites itself with a new program, after performing appropriate setup 5 fork System-Level
    [Show full text]
  • Modern Programming Languages CS508 Virtual University of Pakistan
    Modern Programming Languages (CS508) VU Modern Programming Languages CS508 Virtual University of Pakistan Leaders in Education Technology 1 © Copyright Virtual University of Pakistan Modern Programming Languages (CS508) VU TABLE of CONTENTS Course Objectives...........................................................................................................................4 Introduction and Historical Background (Lecture 1-8)..............................................................5 Language Evaluation Criterion.....................................................................................................6 Language Evaluation Criterion...................................................................................................15 An Introduction to SNOBOL (Lecture 9-12).............................................................................32 Ada Programming Language: An Introduction (Lecture 13-17).............................................45 LISP Programming Language: An Introduction (Lecture 18-21)...........................................63 PROLOG - Programming in Logic (Lecture 22-26) .................................................................77 Java Programming Language (Lecture 27-30)..........................................................................92 C# Programming Language (Lecture 31-34) ...........................................................................111 PHP – Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)........................129 Modern Programming Languages-JavaScript
    [Show full text]
  • Unix Command Line; Editors
    Unix command line; editors Karl Broman Biostatistics & Medical Informatics, UW–Madison kbroman.org github.com/kbroman @kwbroman Course web: kbroman.org/AdvData My goal in this lecture is to convince you that (a) command-line-based tools are the things to focus on, (b) you need to choose a powerful, universal text editor (you’ll use it a lot), (c) you want to be comfortable and skilled with each. For your work to be reproducible, it needs to be code-based; don’t touch that mouse! Windows vs. Mac OSX vs. Linux Remote vs. Not 2 The Windows operating system is not very programmer-friendly. Mac OSX isn’t either, but under the hood, it’s just unix. Don’t touch the mouse! Open a terminal window and start typing. I do most of my work directly on my desktop or laptop. You might prefer to work remotely on a server, instead. But I can’t stand having any lag in looking at graphics. If you use Windows... Consider Git Bash (or Cygwin) or turn on the Windows subsystem for linux 3 Cygwin is an effort to get Unix command-line tools in Windows. Git Bash combines git (for version control) and bash (the unix shell); it’s simpler to deal with than Cygwin. Linux is now accessible in Windows 10, but you have to enable it. If you use a Mac... Consider Homebrew and iTerm2 Also the XCode command line tools 4 Homebrew is a packaging system; iTerm2 is a Terminal replacement. The XCode command line tools are a must for most unixy things on a Mac.
    [Show full text]
  • About ILE C/C++ Compiler Reference
    IBM i 7.3 Programming IBM Rational Development Studio for i ILE C/C++ Compiler Reference IBM SC09-4816-07 Note Before using this information and the product it supports, read the information in “Notices” on page 121. This edition applies to IBM® Rational® Development Studio for i (product number 5770-WDS) and to all subsequent releases and modifications until otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) models nor does it run on CISC models. This document may contain references to Licensed Internal Code. Licensed Internal Code is Machine Code and is licensed to you under the terms of the IBM License Agreement for Machine Code. © Copyright International Business Machines Corporation 1993, 2015. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents ILE C/C++ Compiler Reference............................................................................... 1 What is new for IBM i 7.3.............................................................................................................................3 PDF file for ILE C/C++ Compiler Reference.................................................................................................5 About ILE C/C++ Compiler Reference......................................................................................................... 7 Prerequisite and Related Information..................................................................................................
    [Show full text]
  • Alias Manager 4
    CHAPTER 4 Alias Manager 4 This chapter describes how your application can use the Alias Manager to establish and resolve alias records, which are data structures that describe file system objects (that is, files, directories, and volumes). You create an alias record to take a “fingerprint” of a file system object, usually a file, that you might need to locate again later. You can store the alias record, instead of a file system specification, and then let the Alias Manager find the file again when it’s needed. The Alias Manager contains algorithms for locating files that have been moved, renamed, copied, or restored from backup. Note The Alias Manager lets you manage alias records. It does not directly manipulate Finder aliases, which the user creates and manages through the Finder. The chapter “Finder Interface” in Inside Macintosh: Macintosh Toolbox Essentials describes Finder aliases and ways to accommodate them in your application. ◆ The Alias Manager is available only in system software version 7.0 or later. Use the Gestalt function, described in the chapter “Gestalt Manager” of Inside Macintosh: Operating System Utilities, to determine whether the Alias Manager is present. Read this chapter if you want your application to create and resolve alias records. You might store an alias record, for example, to identify a customized dictionary from within a word-processing document. When the user runs a spelling checker on the document, your application can ask the Alias Manager to resolve the record to find the correct dictionary. 4 To use this chapter, you should be familiar with the File Manager’s conventions for Alias Manager identifying files, directories, and volumes, as described in the chapter “Introduction to File Management” in this book.
    [Show full text]
  • Technical Study Desktop Internationalization
    Technical Study Desktop Internationalization NIC CH A E L T S T U D Y [This page intentionally left blank] X/Open Technical Study Desktop Internationalisation X/Open Company Ltd. December 1995, X/Open Company Limited All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior permission of the copyright owners. X/Open Technical Study Desktop Internationalisation X/Open Document Number: E501 Published by X/Open Company Ltd., U.K. Any comments relating to the material contained in this document may be submitted to X/Open at: X/Open Company Limited Apex Plaza Forbury Road Reading Berkshire, RG1 1AX United Kingdom or by Electronic Mail to: [email protected] ii X/Open Technical Study (1995) Contents Chapter 1 Internationalisation.............................................................................. 1 1.1 Introduction ................................................................................................. 1 1.2 Character Sets and Encodings.................................................................. 2 1.3 The C Programming Language................................................................ 5 1.4 Internationalisation Support in POSIX .................................................. 6 1.5 Internationalisation Support in the X/Open CAE............................... 7 1.5.1 XPG4 Facilities.........................................................................................
    [Show full text]
  • AT Command User Guide 80591ST10886A Rev
    LN940 SERIES AT Command User Guide 80591ST10886A Rev. 1.4 – 2018-04-05 ] 7 .201 Mod. 0806 2017-01 Rev.6 01 [ SPECIFICATIONS ARE SUBJECT TO CHANGE WITHOUT NOTICE NOTICES LIST While reasonable efforts have been made to assure the accuracy of this document, Telit assumes no liability resulting from any inaccuracies or omissions in this document, or from use of the information obtained herein. The information in this document has been carefully checked and is believed to be reliable. However, no responsibility is assumed for inaccuracies or omissions. Telit reserves the right to make changes to any products described herein and reserves the right to revise this document and to make changes from time to time in content hereof with no obligation to notify any person of revisions or changes. Telit does not assume any liability arising out of the application or use of any product, software, or circuit described herein; neither does it convey license under its patent rights or the rights of others. It is possible that this publication may contain references to, or information about Telit products (machines and programs), programming, or services that are not announced in your country. Such references or information must not be construed to mean that Telit intends to announce such Telit products, programming, or services in your country. COPYRIGHTS This instruction manual and the Telit products described in this instruction manual may be, include or describe copyrighted Telit material, such as computer programs stored in semiconductor memories or other media. Laws in the Italy and other countries preserve for Telit and its licensors certain exclusive rights for copyrighted material, including the exclusive right to copy, reproduce in any form, distribute and make derivative works of the copyrighted material.
    [Show full text]