ptg10805159
734 Pseudo Terminals Chapter 19
$who
sar console May 19 16:47
sar ttys000 May 19 16:47
sar ttys001 May 19 16:48
sar ttys002 May 19 16:48
sar ttys003 May 19 16:49
sar ttys004 May 19 16:49 ttys004 is the highest PTY currently in use
$pty ttyname run program in Figure18.16 from PTY
fd 0: /dev/ttys005 ttys005 is the next available PTY
fd 1: /dev/ttys005
fd 2: /dev/ttys005
utmpFile
In Section 6.8, we described theutmpfile that records all users currently logged in to a
UNIX system. The question is whether a user running a program on a pseudo terminal
is considered logged in. In the case of remote logins, withtelnetdandrlogind,
obviously an entry should be made in theutmpfile for the user logged in on the pseudo
terminal. There is little agreement, however,whether users running a shell on a pseudo
terminal from a window system or from a program, such asscript,should have
entries made in theutmpfile. Some systems recordthese; others don’t. If a system
doesn’t recordthese entries in theutmpfile, thewho( 1 )program normally won’t show
the corresponding pseudo terminals as being used.
Unless theutmpfile has other-write permission enabled (which is considered to be
asecurity hole), random programs that use pseudo terminals won’t be able to write to
this file.
Job Control Interaction
If we run a job-control shell underpty, it works normally.For example,
pty ksh
runs the Korn shell underpty.Wecan run programs under this new shell and use job
control just as we do with our login shell. But if we run an interactive program other
than a job-control shell underpty, as in
pty cat
everything is fine until we type the job-control suspend character.Atthat point, the
job-control character is echoed asˆZand is ignored. Under earlier BSD-based systems,
thecatprocess terminates, theptyprocess terminates, and we’reback to our original
shell. Tounderstand what’s going on here, we need to examine all the processes
involved, their process groups, and sessions. Figure19.13 shows the arrangement when
pty catis running.
When we type the suspend character (Control-Z), it is recognized by the line
discipline module beneath thecatprocess, sinceptyputs the terminal (beneath the
ptyparent) into raw mode. But the kernel won’t stop thecatprocess, because it