Terminal Control Many special files represent devices that are platform dependent, making standardization difficult POSIX standards committee decided to.

Slides:



Advertisements
Similar presentations
Linux Serial Programming for POSIX Operating Systems
Advertisements

Chapter 3 Basic Input/Output
INPUT-OUTPUT ORGANIZATION
8086 [2] Ahad. Internal! External? 8086 vs _bit Data Bus 20_bit Address 8_bit Data Bus 20_bit Address Only external bus of 8088 is.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Terminal I/O POSIX termios Two terminal I/O modes Canonical and non-canonical Getting and setting terminal attributes Terminal window size: struct winsize.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
Input/Output Management and Disk Scheduling
Terminal Control operating systems. Terminal Control may seem like an arcane subject, but … It illustrates the relationship between devices and files.
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
CSCI 4550/8556 Computer Networks Comer, Chapter 3: Network Programming and Applications.
Dynamic visualizations On ‘non-canonical’ keyboard-input and terminal escape-sequences for visualization effects.
The TELNET protocol. TELNET vs. telnet TELNET is a protocol that provides “ a general, bi-directional, eight-bit byte oriented communications facility.
Device Management.
Transmission Characteristics 1. Introduction (Information Interchange codes) 2. Asynchronous and Synchronous Transmissions 3. Error detection (bit errors)
Michener’s Algorithm An efficient scheme for drawing circles (and filling circular disks) on a raster graphics display.
Chapter 9: Arrays and Strings
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
Linux game programming An introduction to the use of interval timers and asynchronous input notifications.
Practical Session No. 10 Input &Output (I/O). I/O Devices Input/output (I/O) devices provide the means to interact with the “outside world”. An I/O device.
INPUT-OUTPUT ORGANIZATION
I/O Systems ◦ Operating Systems ◦ CS550. Note:  Based on Operating Systems Concepts by Silberschatz, Galvin, and Gagne  Strongly recommended to read.
Computers in Surveying SVY2301 / E4006 Automated Surveying.
1 Input/Output. 2 Principles of I/O Hardware Some typical device, network, and data base rates.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved OPERATING SYSTEMS DESIGN.
Chapter 5. Connection Controls. Device == File ? Filenames Properties permission bits system call – open, read, write, lseek, close, stat.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
ECS 152A 4. Communications Techniques. Asynchronous and Synchronous Transmission Timing problems require a mechanism to synchronize the transmitter and.
I/O Interfacing A lot of handshaking is required between the CPU and most I/O devices. All I/O devices operate asynchronously with respect to the CPU.
Week 1 Algorithmization and Programming Languages.
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
The tty Interface An introduction to “systems programming” in the Linux environment.
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
AS Computing Data Transmission and Networks. Transmission error Detecting errors in data transmission is very important for data integrity. There are.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Chapter 5 Input/Output 5.1 Principles of I/O hardware
Keyboard and Screens The user interface in unix: simple text based terminals using TERMIOS and CURSES libraries. Ian McCrum.
Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Data Communications and Networking
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
CS-328 Rlogin & Telnet Protocols. Rlogin Remote Logon to another Host RFC 1282 Well known port : 513.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Data Transmission and Networks Transmission error checking & correcting.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
Exercise ● Exercise 4.15: Write a version of mkdir which supports the - p option. Due by class 2/23....
Chapter 1: Introduction to Computers and Programming
The HCS12 SCI Subsystem A HCS12 device may have one or two serial communication interface. These two SCI interfaces are referred to as SCI0 and SCI1. The.
Serial mode of data transfer
CS501 Advanced Computer Architecture
Microprocessor and Assembly Language
Microprocessor Systems Design I
Protection of System Resources
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Object Oriented Programming COP3330 / CGS5409
Chapter 1: Introduction to Computers and Programming
Basic Input and Output C++ programs can read and write information using streams A simple input stream accepts typed data from a keyboard A simple output.
Advanced UNIX programming
Transmitter Interrupts
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Terminal Control Many special files represent devices that are platform dependent, making standardization difficult POSIX standards committee decided to include library functions to manipulate special files representing terminals and asynchronous communications ports

stty stty: Minimum listing of terminal settings stty –a: More complete listing of terminal settings stty –g: Produces terminal settings in a form that can be used by a program and allows you to change them

stty sane Sets all modes to reasonable values Useful if you terminate a program that has set the modes in an inconvenient way – i.e., local echo has been turned off and you can’t see what you are typing If return has been set to carriage return rather than newline, you may have to terminate stty with Ctrl-j rather than return

tcgetattr and tcsetattr SYNOPSIS #incuude Int tcgetattr(int fildes, struct termios *termios_p) Int tcsetattr(int fildes, int optional_actions, const struct termios *termios_p); POSIX Returns 0 if successful. If uncessful, returns –1 and sets errno

tcgetattr and tcsetattr errno errnocause EBADFFildes is not a valid file descriptor EINVALOptional_actions is not a supported value, or attempt to change attribute represented in termios to unsupported value ENOTTYFile associated with fildes is not a terminal

tcgetattr Retrieves attributes associated with the terminal referenced by the open file descriptor fildes Attributes are returned in struct termios structure pointed to by termios_p

tcsetattr Sets parameters of the terminal referenced by the open file descriptor fildes from the termios structure pointed to by termios_p Optional_actions parameger controls the point at which the changes take –TCSANOW – Changes occur immediately –TCSADRAIN – Changes occur after all output to fildes is transmitted –TCSAFLUSH – Changes occur after all output to fides is transmitted (all input received but not read is discarded)

struct termios Programs acces characteristics through the struct termios structure with the following memebers: tcflag_tc-iflag;/* input modes */ tcflag_tc_oflag/* output modes */ tcflag_tc_cflag;/* control modes */ tcflag_tc_lflag;/* local modes */ cc_tc_cc[NCCS];/* control characters */

c_cc array Holds values of characters that have special meaning to terminal device drivers i.e., end of input or program break characters

POSIX Special Control Characters canonical modeNoncanonical modedescriptionUsual default VEOFEOF characterCtrl-D VEOLEOL characternone VERASEERASE characterBackspace or delete VINTR INTR characterCtrl-C VKILLKILL characterCtrl-U VMINMIN value1 VQUIT QUIT characterCtrl-\ VSUSP SUSP characterCtrl-Z VTIMETIME value0 VSTART START characterCtrl-Q VSTOP STOP characterCtrl-S

c_iflag fieldflagdescription c_iflagBRKINTsignal interrupt on break ICRNLmap CR to NL on input IGNBRKignore break condition IGNCRignore CR IGNPARIgnore characters with parity errors INLCRmap NL to CR on input INPCKenable input parity check ISTRIPstrip character IXOFFenable start/stop input control IXONenable start/stop output control PARMRKmark parity errors Controls the way a terminal handles input

c_oflag OPOSTpostprocess output OCRNLmap CR to NL on output (POSIX:XSI Extension) ONOCRno CR output at column 0 (POSIX:XSI Extension) ONLRETNL performs CR function (POSIX:XSI Extension) Controls the way a terminal handles output

c_cflag CSIZEcharacter size (CS5-CS8) for 5 to 8 bits, respectively) CSTOPBsend two stop bits, else one CREADenable receiver PARENBenable parity PARODDodd parity, else even HUPCLhang up on last close CLOCALignore modem status lines Specifies hardware control information for the terminal

c_lflag ECHOenable echo ECHOEecho ERASE as an error-correcting backspace ECHOKenable KILL ECHONLecho a newline ICANONcanonical input (erase and kill processing) IEXTENenable extended (implementation-defined) functions ISIGenable signals NOFLSHdisable flush after interrupt, quit, or suspend TOSTOPsend SIGTTOU for background output Controls the editing functions of the terminal

Setting Flags Set an action by performing a bitwise OR of the appropriate flag Clear an action by performing a bitwise AND with the complement of the flag The following code clears the ECHO flag: Struct termio term: Term.c_flag &= ~ECHO

ttysetchar.c #include #include … int ttysetchar (int fd, int flagname, char c) { int error; struct termios term; if (tcgetattr(fd, Yterm) == –1) return –1; term.c_cc[flagname] = (cc_t)c; while (((error = tcsetattr(fd,TCSAFLUSH,&term)) = –1) && (errno == EINTR)); return error; } … if (ttysetchar(STDIN_FILENO, VEOF, 0x07) == –1) perror(“Failed to change end-of-file character”);

setecho.c #include #include … #define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL) int setecho (int fd, int onflag) { int error; struct termios term; if (tcgetattr9fd, &term) == –1) return –1; if(onflag) term.c_lflag |= ECHOFLAGS;/* turn echo on */ else term.c_lflag &= ~ECHOFLAGS; /* turn echo off */ while (((error=tcsetattr(fd,TCSAFLUSH,&term))== –1)&&(errno==EINTR)); return error; } … setecho(STDIN_FILENO, 0);

Input Processing Keyboard and Screen are not directly connected They are separate devices Device drivers receive bytes from keyboard Bytes are buffered and edited as specified by settings for these devices

Canonical Input The usual method of handling terminal input Process input one line at a time POSIX special control characters (table 6.1) are used to terminate input or perform simple editing A line is a sequence of bytes delimited by newline, end- of-file, or end-of-line Read requests do not return until user enters line delimiter (or process receives a signal) Erase and kill characters work If defined, lines cannot be longer than MAX_CANON Intended for character special files, not block special files

Noncanonical Input Input is not assembled into lines Device driver does not respond to ERASE and KILL characters Has two controlling parameters –MIN – Controls the smallest number of bytes to be gathered before read returns –TIME – Refers to a time with a 0.1 second granularity used for timing out bursty transmissions

MIN/TIME Definitions casemeaning MIN > 0, TIME > 0If TIME expires or MIN bytes are received, read is satisfied MIN > 0, TIME = 0read blocks until at least MIN bytes received MIN = 0, TIME > 0read is satisfied when a single byte arrives or TIME expires MIN = 0, TIME = 0minimum of bytes requested or bytes available are returned

MIN/TIME Examples Assume 5 characters have been typed and you try to read 10 bytes from standard input a.MIN=5, TIME=0 – receive 5 bytes immediately b.MIN=0, TIME=100 – receive 5 bytes immediately c.MIN=20, TIME=100 – receive 5 bytes after 10 seconds d.MIN=3, TIME=100 – receive 5 bytes immediately e.MIN=20, TIME=0 – block until at least 5 more characters are entered f.MIN=0, TIME=0 – receive 5 bytes immediately