The Linux Programming Interface

(nextflipdebug5) #1

1436 Appendix F


Chapter 62


62-1. The tcgetattr() fails if it is applied to a file descriptor that doesn’t refer to a terminal.
62-2. A solution is provided in the file tty/ttyname.c in the source code distribution for
this book.

Chapter 63


63-3. A solution is provided in the file altio/select_mq.c in the source code distribution
for this book.
63-4. A race condition would result. Suppose the following sequence of events: (a) after
select() has informed the program that the self-pipe has data, it performs the
appropriate actions in response to the signal; (b) another signal arrives, and the
handler writes a byte to the self-pipe and returns; and (c) the main program drains
the self-pipe. As a consequence, the program misses the signal that was delivered in
step (b).
63-6. The epoll_wait() call blocks, even when the interest list is empty. This can be useful
in a multithreaded program, where one thread might add a descriptor to the epoll
interest list, while another thread is blocked in an epoll_wait() call.
63-7. Successive epoll_wait() calls cycle through the list of ready file descriptors. This is
useful because it helps prevent file-descriptor starvation, which could occur if
epoll_wait() always (for example) returned the lowest-numbered ready file
descriptor, and that file descriptor always had some input available.

Chapter 64


64-1. First, the child shell process terminates, followed by the script parent process.
Since the terminal is operating in raw mode, the Control-D character is not
interpreted by the terminal driver, but is instead passed as a literal character to
the script parent process, which writes it to the pseudoterminal master. The
pseudoterminal slave is operating in canonical mode, so this Control-D character is
treated as an end-of-file, which causes the child shell’s next read() to return 0, with
the result that the shell terminates. The termination of the shell closes the only file
descriptor referring to the pseudoterminal slave. As a consequence, the next read()
by the parent script process fails with the error EIO (or end-of-file on some other
UNIX implementations), and this process then terminates.
64-7. A solution is provided in the file pty/unbuffer.c in the source code distribution for
this book.
Free download pdf