The tty Interface An introduction to “systems programming” in the Linux environment.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

Linux Serial Programming for POSIX Operating Systems
Linux device-driver issues
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Pemrograman C Risanuri Hidayat. Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Terminal I/O POSIX termios Two terminal I/O modes Canonical and non-canonical Getting and setting terminal attributes Terminal window size: struct winsize.
Pseudo Terminals Concept Application APIs. Overview A pseudo terminal (PTY) is a user level program that appears to be a terminal device to another program.
Chapter One The Essence of UNIX.
MIS 5241 SOFTWARE. MIS 5242 Agenda The Stored Program Concept Software as Control Software as Simulation.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
Terminal Control operating systems. Terminal Control may seem like an arcane subject, but … It illustrates the relationship between devices and files.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Terminal Control Many special files represent devices that are platform dependent, making standardization difficult POSIX standards committee decided to.
An “interactive” application An introduction to “structured” assembly language programming.
Dynamic visualizations On ‘non-canonical’ keyboard-input and terminal escape-sequences for visualization effects.
CS211 Data Structures Sami Rollins Fall 2004.
CS 110 Intro to Computer Science I Sami Rollins Fall 2006.
Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle.
Michener’s Algorithm An efficient scheme for drawing circles (and filling circular disks) on a raster graphics display.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Introduction to windows operating system i
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Guide To UNIX Using Linux Third Edition
CS 101 Problem Solving and Structured Programming in C Sami Rollins Spring 2003.
Linux game programming An introduction to the use of interval timers and asynchronous input notifications.
CIS 260 Computer Programming I in C Prof. Timothy Arndt.
CS 0008 Day 2 1. Today Hardware and Software How computers store data How a program works Operators, types, input Print function Running the debugger.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#6)
COMP Computer Basics Yi Hong May 13, 2015.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
April 14, 2007CCSC-Central Plains Region1 Use of a Simulator and an Assembler in Teaching Input-Output Processing and Interrupt Handling Soe Than Department.
COMP1070/2002/lec3/H.Melikian COMP1070 Lecture #3 v Operating Systems v Describe briefly operating systems service v To describe character and graphical.
Introduction to Computer Programming
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Introduction to Shell Script Programming
Lesson 1. PC vs. Multi-user System  Personal Computer – each user gets his/her own processor (or multicore processor).  Multi-user system – The processor,
Computer Parts Hardware.
Computer Science 101 Introduction to Programming.
Introduction to Computers (L02) * Hardware * Software * Programming Languages * Three Phase of Program Development * Development and Design Steps * Algorithms.
CS 390 Unix Programming Summer Unix Programming - CS 3902 Course Details Online Information Please check.
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
Human-computer interfaces. Operating systems are software (i.e. programs) used to control the hardware directly used to run the applications software.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 Chapter 34 Internet Applications (Telnet, FTP).
Searching and Sorting. Why Use Data Files? There are many cases where the input to the program may come from a data file.Using data files in your programs.
Beginning Snapshots Chapter 0. C++ An Introduction to Computing, 3rd ed. 2 Objectives Give an overview of computer science Show its breadth Provide context.
CMPF124 Basic Skills For Knowledge Workers Chapter 1 – Part 1 Introduction To Windows Operating Systems.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Intermediate 2 Computing Unit 2 - Software Development.
Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.
Computer Software Operating Systems – Programs. Computer Language - Review We learnt that computers are made up of millions of tiny switches that can.
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
Internet and Intranet Protocols and Applications Lecture 6 Application Protocols: Telnet, FTP February 27, 2002 Joseph Conron Computer Science Department.
What is O.S Introduction to an Operating System OS Done by: Hani Al-Mohair.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Sebastián Álvarez Henao.. It refers to all physical parts of a computer system; its components are: electrical, electronic, electromechanical and mechanical.
Introduction to Computer Programming By: Mr. Baha Hanene Chapter 1.
Operating Systems Salihu Ibrahim Dasuki (PhD) CSC102 INTRODUCTION TO COMPUTER SCIENCE.
Exercise ● Exercise 4.15: Write a version of mkdir which supports the - p option. Due by class 2/23....
A LECTURE NOTE.
Windows 94
Computers & Programming Languages
Advanced UNIX programming
4.1 Strings ASCII & Processing Strings with the Functions
Introduction Paul Flynn
Chapter 6 Programming the basic computer
Consult America Technology Consulting Services
Presentation transcript:

The tty Interface An introduction to “systems programming” in the Linux environment

The “login” program An important “interactive” application Illustrates a human-computer dialogue: –Computer says: What’s your name? –User replies: (typing in his/her username) –Computer says: What’s your password? –User replies: (typing in his/her password) –Computer performs a “lookup” operation –Computer replies: ok, access is allowed (or alternatively: access is denied)

Login program-structure main process_dataprint_outputobtain_input We saw this same basic program-structure once before (i.e., in our ‘manydots.s’ demo)

But ‘login’ needs a ‘tweak’ Login requires user to type a password The password is supposed to be secret But computer prints it onscreen (‘echo’) Anyone passing by will know the secret! How can we stop the ‘automatic echo’? It is a “systems programming” problem

How does the ‘tty’ work? TeleType displaY device HARDWARE SOFTWARE application tty_driver c_lflag input handling c_iflag c_cc output handling c_oflag terminal_driver c_cflag User space Kernel space struct tty { c_iflag; c_oflag; c_cflag; c_lflag; c_line; c_cc[ ]; };

The ‘c_lflag’ field It’s an array of flag-bits Individual bits have symbolic names Names conform to a POSIX standard Linux names match other UNIX’s names Though actual symbol-values may differ Your C/C++ program should use: #include for portability to other UNIX environments

The ‘c_lflag’ field (continued) Symbolic names defined in a header-file Header-files are in ‘/usr/include’ directory (and in its sub-directories) Important flag-bit names: ECHO, ECHONL You can search for them (by using ‘grep’): – $ grep ECHO /usr/include/*.h – $ grep ECHO /usr/include/*/*.h ECHO is in ‘/usr/include/asm/termbits.h’

How to turn off tty echo Two programming interface-functions: –int tcgetattr( int fd, struct termios *tios ); –Int tcsetattr( int fd, int fl, struct termios *tios ); Algorithm: –Use ‘tcgetattr()’ to get current settings –Clear the ECHO flag in c_lflag –Set the ECHONL flag in c_lflag –Use ‘tcsetattr()’ to install new settings

Demo ‘noecho.cpp’ High-level language: briefer and clearer So we use C++ to demonstrate this idea We worry later about assembly language A minor side-issue: converting ascii codes for letters from lowercase to uppercase Helps to know the C++ logic operators

AND, OR, XOR, NOT Important C++ operators: &, |, ^, and ~ Needed often in systems programming Examples (used in ‘noecho.cpp’): c_lflag &= ~ECHO; c_lflag |= ECHONL; Useful also for converting letters from lowercase to uppercase (or vice-versa)