Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

742 Pseudo Terminals Chapter 19


Exercises


19.1 When we remotely log in to a BSD system using eithertelnetorrlogin,the ownership
of the PTY slave and its permissions areset, as we described in Section 19.3. How does
this happen?
19.2 Use theptyprogram to determine the values used by your system to initialize a slave
PTY’stermiosstructureandwinsizestructure.
19.3 Recode theloopfunction (Figure19.12) as a single process using eitherselectorpoll.
19.4 In the child process afterpty_fork returns, standardinput, standardoutput, and
standarderror areall open for read–write. Can you change standardinput to be read-only
and the other two to be write-only?
19.5 In Figure19.13, identify which process groups are in the foreground and which are in the
background, and identify the session leaders.
19.6 In Figure19.13, in what order do the processes terminate when we type the end-of-file
character? Verify this with process accounting, if possible.
19.7 Thescript( 1 )program normally adds to the beginning of the output file a line with the
starting time, and to the end of the output file another line with the ending time. Add
these features to the simple shell script that we showed.
19.8 Explain why the contents of the filedataareoutput to the terminal in the following
example, even though the programttyname(Figure18.16) only generates output and
never reads its input.
$ cat data afile with two lines
hello,
world
$ pty -i < data ttyname -i says ignoreeof on stdin
hello, wheredid these two lines come from?
world
fd 0: /dev/ttys005 we expect these three lines from ttyname
fd 1: /dev/ttys005
fd 2: /dev/ttys005

19.9 Write a program that callspty_forkand have the childexecanother program that you
will write. The new program that the childexecsmust catchSIGTERMandSIGWINCH.
When it catches a signal, the program should print that it did; for the latter signal, it should
also print the terminal’s window size. Then have the parent process send theSIGTERM
signal to the process group of the PTY slave with theioctlcommand we described in
Section 19.7. Read back from the slave to verify that the signal was caught. Follow this
with the parent setting the window size of the PTY slave, and then read back the slave’s
output again. Have the parentexitand determine whether the slave process also
terminates; if so, how does it terminate?
Free download pdf