Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bbn!rochester!PT.CS.CMU.EDU!sei!sei.cmu.edu!pdb From: pdb@sei.cmu.edu (Patrick Barron) Newsgroups: comp.unix.questions Subject: Re: What is the name of /dev/tty? Message-ID: <2903@aw.sei.cmu.edu> Date: Sun, 18-Oct-87 01:53:23 EDT Article-I.D.: aw.2903 Posted: Sun Oct 18 01:53:23 1987 Date-Received: Sun, 18-Oct-87 22:56:24 EDT References: <1418@zyx.UUCP> Sender: netnews@sei.cmu.edu Reply-To: pdb@sei.cmu.edu (Pat Barron) Organization: Carnegie-Mellon University, SEI, Pgh, Pa Lines: 23 In article <1418@zyx.UUCP> aj@zyx.SE (Arndt Jonasson) writes: > >Is there any way in Unix (either BSD or SYS5) to obtain the true name >of the process's controlling terminal? On 4BSD, you can find out the terminal connected to /dev/tty by digging it out of your process's u area. If you don't have read access to /dev/kmem, your process can fork off a child temporarily, and use ptrace(2) to get at the info. This will yield the major and minor device numbers of the controlling tty (or zero, if your process isn't attached to a terminal). You could also look for your own entry in /etc/utmp the way "who am i" does. >The reason why it would be interesting to know this is that I want my >program to know whether its standard output and its controlling terminal >are the same, in the sense that output to the two streams will mix on >the same window/screen. Error messages will use /dev/tty only if it is >not the same as stdout, to avoid mixing of output from different write >operations on the screen. Why not just use stderr for error messages instead? --Pat.