Solved

Attach daemon to a tty

Posted on 1997-04-16
5
1,400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 95
Question regarding Copy/Paste 16 97
Best tools for Backup and restore of Wordpress site 6 58
tripleUp challenge 7 92
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

680 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