Problem
I am dialed into a machine and press <Ctrl> D. However, the modem
doesn't always hang up. I sometimes get "+++AT" commands displayed
on my screen. What happens after I press <Ctrl> D, and why do I get
the modem commands displayed? Cause
Modems that use the Hayes instruction set use the "+++" characters
to instruct the modem to go into command mode. A "guard time"
prevents this string from being recognized if embedded in a
continuous stream of characters sent to the modem, but sending +++
by itself can cause a user to accidentally or intentionally access
the modem's command mode, which should not be allowed. To prevent
this, the dialers disable this function. The modem is instructed
to disallow command mode from being entered again until DTR is
dropped (at which point it is automatically entered).Ctrl-D causes the shell to read 0 characters of input, which it
interprets as EOF (end of file). This causes the shell to exit.
When the last file descriptor for a tty is closed, DTR is dropped.
This returns the modem to command mode, in which it interprets the
AT commands.If you execute a background process from a login session, the shell
will exit but the background process will still have file descriptors
open for the tty associated with the login, therefore DTR will not
drop. When the AT commands are sent, they will be transmitted by
the modem instead of being interpreted as commands to the modem
itself. Solution
Change the application that is still running so that it doesn't
use a file descriptor associated with a tty. The most common tty
file descriptors are 0, 1, and 2 (standard in, standard out and
standard error). In most cases, issuing the command in the
following manner will close all of its tty file descriptors. This
may cause problems with the application if the application tries to
write to its standard output or standard error and the write fails
because they are closed.<command> <&- >&- 2>&-<&- closes the standard input (file descriptor 0) >&- closes the standard output (file descriptor 1) 2>&- closes the standard error (file descriptor 2)
The other alternative is to stay logged in until the application completes execution, or to modify the application so that it closes the file descriptors that it inherits from the shell.
See also
The HUPCL parameter in termio(M), sh(C), and your modem's manual.