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.

Slides:



Advertisements
Similar presentations
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
Advertisements

Terminal I/O POSIX termios Two terminal I/O modes Canonical and non-canonical Getting and setting terminal attributes Terminal window size: struct winsize.
NCHU System & Network Lab Lab 15 Record Locking. NCHU System & Network Lab Record Locking (1/4) What happens when two process attempt to edit the same.
Process Relationships Terminal and Network Logins Process Groups and Sessions Job Control Relationships.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
1 Processes and Pipes. 2 "He was below me. I saw his markings, manoeuvred myself behind him and shot him down. If I had known it was Saint-Exupery, I.
Exec function Exec function: - replaces the current process (its code, data, stack & heap segments) with a new program - the new program starts executing.
Daemon Processes and inetd Superserver
CSE 451 Section 4 Project 2 Design Considerations.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
Unix Processes Slides are based upon IBM technical library, Speaking Unix, Part 8: Unix processes Extended System Programming Laboratory (ESPL) CS Department.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
Agenda  Terminal Handling in Unix File Descriptors Opening/Assigning & Closing Sockets Types of Sockets – Internal(Local) vs. Network(Internet) Programming.
Unix Pipes Pipe sets up communication channel between two (related) processes. 37 Two processes connected by a pipe.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty for every terminal device invokes our login shell terminal.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Minishell InKwan Yu Topics Unix System calls waitpid() pipe() dup2() C function calls strtok() strcmp() Minishell Software Enginnering.
System Commands and Interprocess Communication. chroot int chroot(const char *path); chroot changes the root directory to that specified in path. This.
Pipes A pipe is a simple, synchronized way of passing information between processes A pipe is a special file/buffer that stores a limited amount of data.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
CS162B: Pipes Jacob T. Chan. Pipes  These allow output of one process to be the input of another process  One of the oldest and most basic forms of.
Agenda  Redirection: Purpose Redirection Facts How to redirecting stdin, stdout, stderr in a program  Pipes: Using Pipes Named Pipes.
Shell (Addendum). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
1 Daemons & inetd Refs: Chapter Daemons A daemon is a process that: –runs in the background –not associated with any terminal Unix systems typically.
Operating Systems Process Creation
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
Interprocess Communication Anonymous Pipes Named Pipes (FIFOs) popen() / pclose()
Advanced Programming in the UNIX Environment Hop Lee.
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Process Management Azzam Mourad COEN 346.
Chapter 1 Introduction  What is an operating system  History of operating systems  The operating system zoo  Computer hardware review  Operating system.
CSCI 330 UNIX and Network Programming
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
UNIX Network Programming1 Chapter 12. Daemon Processes and inetd Superserver.
OS Labs 2/25/08 Frans Kaashoek MIT
CSC414 “Introduction to UNIX/ Linux” Lecture 3
Dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala.
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
Unix Basics.
Week 3 Redirection, Pipes, and Background
CS 3305A Process – Part II Lecture 4 Sept 20, 2017.
UNIX System Overview.
System Structure and Process Model
System Structure and Process Model
Fork and Exec Unix Model
System Structure B. Ramamurthy.
File redirection ls > out
Pipes A pipe provides a one-way flow of data example: who | sort| lpr
LINUX System Programming with Processes (additional)
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
CGS 3763 Operating Systems Concepts Spring 2013
2/25/08 Frans Kaashoek MIT OS abstractions 2/25/08 Frans Kaashoek MIT
Programming Assignment # 2 – Supplementary Discussion
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
IPC Prof. Ikjun Yeom TA – Hoyoun
Today’s topic UNIX process relationship and job control
Daemons & inetd Refs: Chapter 12.
CSCI 380: Operating Systems William Killian
Standard I/O Library Implementation
Chapter 12: File-System Implementation CSS503 Systems Programming
Intro to the Shell with Fork, Exec, Wait
Presented by, Mr. Satish Pise
Presentation transcript:

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 A pseudo terminal has two bidirectionally connected ends, the master and the slave slave is connected to the program that thinks its connected to a terminal device master is connected to the program that is providing this pseudo terminal service

Typical Pseudo Terminal Arrangement

Steps Process opens pseudo terminal master and calls fork Child creates new session, opens corresponding pseudo terminal slave, duplicates fd of terminal slave to stdin, stdout, stderr and then calls exec Pseudo terminal slave becomes the controlling terminal for the child It appears to the user process above the slave that it is connected to a terminal device Output from the master appears as input to the slave and vice versa

Applications Network login (telnetd, sshd, etc) The script utility X Windows etc

Applications – Network Login

Network login requests come in through the network interface driver inetd. rlogind is started per request rlogind opens a pseudo terminal master and then forks Child duplicates file descriptors 0, 1 and 2 to the pseudo terminal then execs login Parent and child communicate through the pseudo terminal Note that the process connected to the master is also reading/writing another I/O stream at the same time. This implies multiplexed I/O (select or poll)

Applications – script utility

The script utility places itself between the terminal and a new copy of the login shell While running, all the output from the terminal line descriptor above the PTY slave is copied into a script file Input that is echoed is also stored

Pseudo Terminal Interfaces Historically there were two main pseudo terminal APIs BSD System V (aka UNIX98) LINUX supports both, but since kernel BSD APIs are deprecated. Use UNIX98 interface instead

UNIX98 Pseudo Terminals int posix_openpt(int flags); Opens an unused UNIX98 PTY master flags can the OR zero or more of O_RDWR and O_NOCTTY int grantpt(int fd); Sets permissions of the slave PTY int unlockpt(int fd); Unlocks the slave PTY corresponding to the master PTY designated by fd char *ptsname(int fd); Returns the pathname of the PTY device based on the FD of the master

UNIX98 Pseudo Terminals Limits on number of PTY devices Default limit is 256 Can be changed by re-compiling the kernel up to 4096 Two files under /proc/sys/kernel/pty max – the max pairs of PTYs nr – number of PTYs currently in use

BSD Pseudo Terminals BSD style PTYs come as pre-created pairs /dev/ptyXY (master) /dev/ttyXY (slave) X is one letter from [p-z,a-e] Y is one letter from [0-9,a-f] Ex: /dev/ptyp1 and /dev/ttyp1 are a PTY pair Process opens a PTY by trying master devices sequentially until it can open one then opening the corresponding slave

GLIBC PTY Library Calls glibc provides openpty and forkpty int openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize * winp); Opens a master slave pair and optionally uses termios and winsize to set up the slave tty. pid_t forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp); Combines openpty and fork Returns pid of 0 in child and actual pid in parent like regular fork function