How to make a process connect to a p-tty

How to make a process connect to a p-tty

Post by Robert Sandfo » Mon, 15 Apr 1996 04:00:00



   I been working on a shell program that allows a user to telnet to a port on their
machine and login to this shell

  telnet mycomputer 2345

  Once the user is on the shell they are able to do just about all the commands a normal
shell would have. The only problem I am having is getting the process to connect to a tty
so the user can use write, talk and other programs that need to be connected to a tty.

  I asked several "expert" Unix & C programmers this question but they were only to give me
a vague answer since they have never done this themselves. I looked in man pages and in about
15 different C programming books and still have no idea what to do.

  Any help or an example of a process connecting to a tty would be greatly appreciated.

 Robert Sandford

 
 
 

How to make a process connect to a p-tty

Post by Patrick Horg » Thu, 18 Apr 1996 04:00:00



   ... some stuff cut ...
Quote:>shell would have. The only problem I am having is getting the process to connect to a tty
>so the user can use write, talk and other programs that need to be connected to a tty.

Robert, what you want to do is to create a pseudo tty.  This is done a bit
differently depending on whether you're going to do it on a bsd system or on
a SYSV system.  I encourage you to read the appropriate sections of Rich Stevens'
Advanced Programming in the UNIX environment.  If you don't have access to it, or
don't understand it, please feel free to email me and I can send you some sample
code.  I believe you'll get a lot more out of it if you research it yourself
though.   It's not very *ce you get the basic concept.  You'll like it:)
The basic idea is that you open the master side of the pty on the daemon side,
fork, the child opens the child side of the pty as their stdout/stdin/stderr,
then execs whatever program you want to run.

To the program running as the child it looks like they have a tty, but everything
they write to it shows up at the master side of the pty where you can feel free
to read it and copy it down the socket hooked to your client.

--


   Opinions mine, not my employer's except by most bizarre coincidence.

 
 
 

1. How does ps(1) get process controlling tty?

The c.u.p FAQ has a great little code fragment for implementing a
ps(1) like program that enumerates running processes and gets the
appropriate user and proc structures for them.

One thing it is missing is how to get the controlling terminal for the
processes.  If I trace ps, I see it rummage about in /etc/psdatabase,
but I have no idea what the file format is, or if that is even where
it gets the tty info from.

Can someone tell me how to find the tty associated with an arbitrary
process in SunOS given a user or proc structure?  ttyname() is of no
use, since it only works for the calling process.  I need to embed it
in a loop like the  FAQ ps example.

Thanks.


2. Running a command in another shell

3. ps list and process tty's

4. transferring Netscape bookmark files

5. Making a Process Table (like ps)

6. Merced project

7. How can I re-connect the orphan background process to my current tty?

8. Lpstat....Lsallq???

9. Several processes connected to /dev/tty

10. tty-less processes with tty's open

11. Why ps -ef lists my current process but ps -e does not?

12. Making DIP release tty line...

13. making an AIX box to call me via tty/modemline