PTY(7) Linux Programmer’s Manual PTY(7) 名前 pty - 擬似端末インタフェース 説明 擬似端末 (pseudo-terminal) は、双方向通信チャンネルを提供する仮想キャラ クタデバイスのペアである。チャンネルの一方の端点は マスタ (master) と呼 ば れ、もう一方の端点は スレーブ (slave) と呼ばれる。擬似端末のスレーブ は、伝統的な端末と全く同じ動作をするインタフェースを提供する。端末に 接 続 されることを想定しているプロセスは擬似端末のスレーブをオープンするこ とができ、それ以降はマスタ側をオープンしているプログラムからそのプロ セ ス を制御することができる。端末で入力されたのと同じように、マスタ側に書 き込まれた全てのデータは、スレーブ側のプロセスに送られる。例えば、マ ス タ デバイスに割り込みキャラクタ (通常は control-C) を書き込むと、スレー ブに接続されているフォアグラウンド・プロセスグループに対して割り込み シ グ ナル (SIGINT) が生成される。反対に、擬似端末のスレーブ側に書き込まれ た全てのデータは、マスタ側に接続されているプロセスから読み出すことが で きる。擬似端末は、ネットワークログインサービス (ssh(1), rlogin(1), tel- net(1)) や端末エミュレータ、 script(1), screen(1), expect(1) などのアプ リケーションで使用されている。 歴史的に見ると BSD と System V の2種類の擬似端末の API が発展してきてい る。 SUSv1 は System V API に基づいた擬似端末 API を標準化しており、 擬 似端末を使用する新しいプログラムはすべてこの API を採用すべきである。 Linux では BSD 風と (標準化された) System V 風の擬似端末を提供している 。 System V 風の端末は、Linux システムでは一般に Unix 98 擬似端末と呼ば れている。カーネル 2.6.4 以降では、BSD 風の擬似端末は廃止予定とみなされ ている (カーネルのコンフィギュレーションで BSD 風の擬似端末を無効にする ことができる)。新しいアプリケーションでは、Unix 98 擬似端末を使用すべき である。 Unix 98 擬似端末 未使用の Unix 98 擬似端末マスタをオープンするには posix_openpt(3) を 呼 び 出 す ( この関数はマスタ・クローン・デバイス (master clone device), /dev/ptmx をオープンする; pts(4) を参照)。プログラム固有の初期化処理 を 実 行 し 、 grantpt(3) を使ってスレーブデバイスの所有権や許可を変更し、 unlockpt(3) を使ってスレーブのロック解除を行うと、 ptsname(3) が返す 名 前を渡して open(2) を呼び出すことにより対応するスレーブデバイスをオープ ンできるようになる。 Linux カーネルでは、利用できる Unix 98 擬似端末の数に上限を設けている。 2.6.3 以前のカーネルでは、この上限はカーネルのコンパイル時の設定 (CON- FIG_UNIX98_PTYS) である。許可される擬似端末の数は最大 2048 であり、デフ ォ ル ト の 設 定 は 256 である。カーネル 2.6.4 以降では、この上限は /proc/sys/kernel/pty/max 経由で動的に調整可能となって い る 。 ま た 、 /proc/sys/kernel/pty/nr で現在使用中の擬似端末の数を取得できる。この 2 つのファイルの詳細は proc(5) を参照。 BSD 擬似端末 BSD 風の擬似端末はあらかじめ作成されたペアとして提供される。その名前 は /dev/ptyXY ( マスタ側)、 /dev/ttyXY (スレーブ側) である。ここで、 X は [p-za-e] の 16文字のうちの一文字、 Y は [0-9a-f] の 16文字のうちの一 文 字 である (X, Y に使われる文字の正確な範囲は Unix の実装により異なる)。 例えば、 /dev/ptyp1 と /dev/ttyp1 は BSD 擬似端末ペアを構成する。プロセ スが未使用の擬似端末ペアを見つけるには、各擬似端末のマスタの open(2) を 試み、open が成功するまでこれを繰り返す。マスタを open すると、対応する 擬 似端末のスレーブも open できるようになる (スレーブの名前は、マスタの 名前の "pty" を "tty" に置き換えたものである)。 ファイル /dev/ptmx (Unix 98 マスタ・クローン・デバイス) /dev/pts/* (Unix 98 スレーブデバイス) /dev/pty[p-za-e][0-9a-f] (BSD マスタデバイス) /dev/tty[p-za-e][0-9a-f] (BSD スレーブデバイス) 注意 パケット・モード操作の制御を行う TIOCPKT ioctl(2) の説明は tty_ioctl(4) に書かれている。 BSD ioctl(2) の TIOCSTOP, TIOCSTART, TIOCUCNTL, TIOCREMOTE はこれまでの ところ Linux では実装されていない。 関連項目 select(2), setsid(2), forkpty(3), openpty(3), termios(3), pts(4), tty(4), tty_ioctl(4) Linux 2005-10-10 PTY(7)
PTY(7) Linux Programmer’s Manual PTY(7) NAME pty - pseudo-terminal interfaces DESCRIPTION A pseudo-terminal is a pair of virtual character devices that provide a bidirectional communication channel. One end of the channel is called the master; the other end is called the slave. The slave end of the pseudo-terminal provides an interface that behaves exactly like a clas- sical terminal. A process that expects to be connected to a terminal, can open the slave end of a pseudo-terminal and then be driven by a program that has opened the master end. Anything that is written on the master end is provided to the process on the slave end as though it was input typed on a terminal. For example, writing the interrupt character (usually control-C) to the master device would cause an interrupt signal (SIGINT) to be generated for the foreground process group that is connected to the slave. Conversely, anything that is written to the slave end of the pseudo-terminal can be read by the pro- cess that is connected to the master end. Pseudo-terminals are used by applications such as network login services (ssh(1), rlogin(1), tel- net(1)), terminal emulators, script(1), screen(1), and expect(1). Historically, two pseudo-terminal APIs have evolved: BSD and System V. SUSv1 standardized a pseudo-terminal API based on the System V API, and this API should be employed in all new programs that use pseudo-termi- nals. Linux provides both BSD-style and (standardized) System V-style pseudo- terminals. System V-style terminals are commonly called Unix 98 pseudo-terminals on Linux systems. Since kernel 2.6.4, BSD-style pseudo-terminals are considered deprecated (they can be disabled when configuring the kernel); Unix 98 pseudo-terminals should be used in new applications. Unix 98 pseudo-terminals An unused Unix 98 pseudo-terminal master is opened by calling posix_openpt(3). (This function opens the master clone device, /dev/ptmx; see pts(4).) After performing any program-specific initial- izations, changing the ownership and permissions of the slave device using grantpt(3), and unlocking the slave using unlockpt(3)), the cor- responding slave device can be opened by passing the name returned by ptsname(3) in a call to open(2). The Linux kernel imposes a limit on the number of available Unix 98 pseudo-terminals. In kernels up to and including 2.6.3, this limit is configured at kernel compilation time (CONFIG_UNIX98_PTYS), and the permitted number of pseudo-terminals can be up to 2048, with a default setting of 256. Since kernel 2.6.4, the limit is dynamically adjustable via /proc/sys/kernel/pty/max, and a corresponding file, /proc/sys/kernel/pty/nr, indicates how many pseudo-terminals are cur- rently in use. For further details on these two files, see proc(5). BSD pseudo-terminals BSD-style pseudo-terminals are provided as pre-created pairs, with names of the form /dev/ptyXY (master) and /dev/ttyXY (slave), where X is a letter from the 16-character set [p-za-e], and Y is a letter from the 16-character set [0-9a-f]. (The precise range of letters in these two sets varies across Unix implementations.) For example, /dev/ptyp1 and /dev/ttyp1 constitute a BSD pseudo-terminal pair. A process finds an unused pseudo-terminal pair by trying to open(2) each pseudo-termi- nal master until an open succeeds. The corresponding pseudo-terminal slave (substitute "tty" for "pty" in the name of the master) can then be opened. FILES /dev/ptmx (Unix 98 master clone device) /dev/pts/* (Unix 98 slave devices) /dev/pty[p-za-e][0-9a-f] (BSD master devices) /dev/tty[p-za-e][0-9a-f] (BSD slave devices) NOTES A description of the TIOCPKT ioctl(2), which controls packet mode oper- ation, can be found in tty_ioctl(4). The BSD ioctl(2) operations TIOCSTOP, TIOCSTART, TIOCUCNTL, and TIOCRE- MOTE have not been implemented under Linux. SEE ALSO select(2), setsid(2), forkpty(3), openpty(3), termios(3), pts(4), tty(4), tty_ioctl(4) COLOPHON This page is part of release 3.22 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2005-10-10 PTY(7)
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa