Solved

Attach daemon to a tty

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now