Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Attach daemon to a tty

Posted on 1997-04-16
5
1,382 Views
Last Modified: 2013-12-26
I would like to attach a process with no controlling tty to a tty. i.e. the process should be able to open /dev/tty.
I looked in kernel sources (Linux) and did not find any way to do this directly, however I found a mention of slave ptys, which seem like they might do something similar.
Opening /dev/console is not an acceptable solution, as this should be possible to do in the background.
The target application is a SVGALib daemon, drawing to a specified tty on request.
0
Comment
Question by:msharov
5 Comments
 
LVL 3

Expert Comment

by:dhm
ID: 1292595
Since the application draws to a tty "on request," couldn't you just include the name of the tty in the request?  The daemon can open the tty named in the request; that terminal becomes the daemon's controlling tty unless you specify extra flags to the open().  (I can dig up the exact flags and other info if this is an acceptable solution.)
0
 

Author Comment

by:msharov
ID: 1292596
That's not true. Only one process group at a time can have the tty as its controlling tty. If you open a used tty, /dev/tty is still owned by the active process in the previous process group and cannot be opened by the daemon.
0
 

Expert Comment

by:wjg
ID: 1292597
Why do you want the terminal you open to write to as your controlling tty? Writing to/Reading from a tty should be possible, even if it is not your controlling tty. (If you use a job-control shell: some of them configure the tty driver to suspend processes that are not in the tty's process group. Usually stty(1) or ioctl(2)/termios(2), or shell builtin commands can be used to allow writing to all processes wanting to do so. See the mesg(1) command, and write(1) as well as wall(1m)).

How are you going to synchronize writes to the user's terminal (i.e. who is 'requesting the drawing' - the user or another daemon)? You should not mess around with the user's current tty settings as these may be from a screen oriented program the user is currently using (like vi/more). If the user calls one of your programs to establish contact to the daemon running in the background this program could either provide information on the process group it is in and the tty name (which is what dhm already noticed) or you could split up work differently by having the user started application do the drawing of data received from the daemon.

0
 

Expert Comment

by:wjg
ID: 1292598
Rereading your question and my comment the following thought just occurred to me: Do you know the difference between /dev/tty (i.e. a pseudo device that maps to the calling users controlling tty) and /dev/tty?* (i.e. devices that represent serial lines or pseudo terminals on the screen)? If you want to use /dev/tty you really do have a problem because what you should be using is the callers *real* terminal as returned by tty(1) - which is the /dev/tty?* variety.
0
 
LVL 4

Accepted Solution

by:
jos010697 earned 200 total points
ID: 1292599
Use pseudo terminals. Check your /dev directory and
see how many pseudo terminals are defined. Every
pseudo terminal is represented by two drivers:

/dev/ptyX   the controlling driver
/dev/ttyX   the slave device driver

if one process opens the controlling driver and another
opens the slave driver, communication between the two
can done by 'pseudo' terminals, i.e. wrtiten data to one device
can be read (by the other process) from the other device.

kind regards,

Jos

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question