Tty - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Tty

Description:

The POSIX specification has provided new interfaces for handling process groups. ... Tty POSIX implementation. int tcsetpgrp(int tty, int foreground_group) ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 10
Provided by: ziv3
Category:
Tags: posix | tty

less

Transcript and Presenter's Notes

Title: Tty


1
Tty
2
What is a tty?
  • tty (terminal type) is UNIXs way to define a
    terminal.
  • The tty system call prints the path name of the
    user's terminal (e.g. /dev/pts/89).
  • On LINUX each terminal opened (Eterm, Xterm,
    Gnome, etc.) has its own tty.

3
Process Groups and tty management
  • One of the areas least-understood by most UNIX
    programmers is process-group management, a topic
    that is inseparable from signal-handling.
  • To understand why process-groups exist, think
    back to the world before windowing systems.

4
Process Groups and tty management
  • Your average user wants to run several programs
    simultaneously. Obviously you cannot have two
    processes reading from the same tty at the same
    time, they'll each get some of the characters you
    type. Likewise output should be managed.
  • This has been a problem with many operating
    systems.

5
Tty - Solutions
  • Tenex and TOPS-20 - used process stacks. You
    could interrupt a process to run another process,
    and when the new process was finished the old
    would restart.
  • While this was useful it didn't allow you to
    switch back and forth between processes without
    exiting one of them.
  • Clearly there must be a better way.

6
Tty SolutionsThe Berkeley approach
  • The Berkeley UNIX folks came up with a different
    idea, called process groups.
  • The tty has a concept of "foreground process
    group", the group of processes which is allowed
    to do input and output to the tty.
  • A set of processes has a tty device to which it
    belongs, called its "controlling tty". This tty
    device is what is returned when /dev/tty is
    opened.

7
  • The tty watches for particular key presses (Z
    usually) and sends a signal to the foreground
    process group when it sees one. All processes in
    the group see the signal, and all stop -
    returning the control to the shell.
  • At this point the shell can place any of the
    active process groups back in the foreground.
  • To handle the case where a background process
    tries to read or write from the tty, the tty
    driver will send a SIGTTIN or SIGTTOU signal to
    any background process which attempts to perform
    such an operation. Under normal circumstances
    only the foreground processes can use the tty.

8
Tty POSIX implementation
  • The POSIX specification has provided new
    interfaces for handling process groups.
  • int setpgid(int process_id, int process_group)
  • Move a process into a new process group.
  • int getpgid(int process_id)
  • Find the process group of a process.
  • int getpgrp(void)
  • Find the process group of the current process.

9
Tty POSIX implementation
  • int tcsetpgrp(int tty, int foreground_group)
  • Change the foreground process group of a tty.
  • int tcgetpgrp(int tty, int foreground_group)
  • Find the foreground process group of a tty.
  • int kill(int -process_group, int signal_number)
  • Send a signal to a process group. Note that
    process_group must be passed as a negative value.
Write a Comment
User Comments (0)
About PowerShow.com