Technical article 105329

Why doesn't the modem hang up when I press <Ctrl> D? DTR doesn't drop.

OpenServer 5.0.0OpenServer 5.0.2OpenServer 5.0.4OpenServer 5.0.5OpenServer 5.0.6

Written · Last revised

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.

From the Xinuos technical article database, record 105329. Reproduced with permission. The original is at www.sco.com/ta/105329, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.