Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I use PTY's

98 views
Skip to first unread message

A.Windram

unread,
Sep 24, 2002, 1:23:28 PM9/24/02
to
I have an app written for DEC UNIX (OSF) which uses PTY's and I am trying to
port it to LINUX (initially Red Hat 7.2).

OSF has nice things like openpty() and forkpty() but I cannot find similar
things in LINUX, although there is a
/dev/ptmx
However, I don't know how to use this.

Can anyone point me at a code example of how to allocate and use pty's under
LINUX? Or should I be using pts's and if so, how do I do this?

I'd be grateful for any pointers!

Alistair Windram


Kasper Dupont

unread,
Sep 24, 2002, 3:51:57 PM9/24/02
to

If anybody comes with a good answer, I will add it to the FAQ:
http://www.daimi.au.dk/~kasperd/comp.os.linux.development.faq.html#ptmx

I think I posted some example program once, but all I could
find was two lines of code.

--
Kasper Dupont -- der bruger for meget tid på usenet.
For sending spam use mailto:aaa...@daimi.au.dk
or mailto:mcxumhv...@skrammel.yaboo.dk

Pete Zaitcev

unread,
Sep 24, 2002, 8:45:16 PM9/24/02
to
On Tue, 24 Sep 2002 18:23:28 +0100, A.Windram <alistair...@bbsrc.ac.uk> wrote:
> OSF has nice things like openpty() and forkpty() but I cannot find similar
> things in LINUX, although there is a
> /dev/ptmx
> However, I don't know how to use this.

[zaitcev@niphredil tmp]$ nm /usr/lib/libutil.a | grep openpty
openpty.o:
00000000 T openpty
U openpty
[zaitcev@niphredil tmp]$ cat /etc/redhat-release
Red Hat Linux release 7.3 (Valhalla)
[zaitcev@niphredil tmp]$

I source is pretty transparent, though I ever used it from a
JNI class. There's about 3..4 lines of example code in this:
http://people.redhat.com/zaitcev/java/jta20-p3-20001109.diff

-- Pete

Kevin Easton

unread,
Sep 24, 2002, 10:53:11 PM9/24/02
to

/dev/ptmx is the master multiplexer for Unix98-style PTYs - the idea is
you open /dev/ptmx, use the TIOCGPTN ioctl on it to find the pseudo
terminal number, then open the slave device at /dev/pts/NNN where NNN is
that number.

On the other hand, if you #include <pty.h> then you get openpty and
forkpty. Probably that's the way to go for porting...

- Kevin.

Ilja Tabachnik

unread,
Sep 25, 2002, 4:15:10 AM9/25/02
to
A.Windram wrote:

> I have an app written for DEC UNIX (OSF) which uses PTY's and I am trying
> to port it to LINUX (initially Red Hat 7.2).
>
> OSF has nice things like openpty() and forkpty() but I cannot find similar
> things in LINUX, although there is a
> /dev/ptmx
> However, I don't know how to use this.
>
> Can anyone point me at a code example of how to allocate and use pty's
> under LINUX? Or should I be using pts's and if so, how do I do this?
>

Try 'info libc Pseudo-Terminals' on your Linux system,
on my Slackware 8.1 it shows code examples etc.

Ilja.

A.Windram

unread,
Sep 26, 2002, 8:14:24 AM9/26/02
to

"A.Windram" <alistair...@bbsrc.ac.uk> wrote in message
news:amq72i$8rq$1...@south.jnrs.ja.net...

Many thanks to all who replied. I got pointers to code examples from Bob
Lynch, which do basic direct allocation of the /dev/ptyXX devices, and look
like they should work. However, I am fairly well convinced that I should use
openpty() and forkpty() by including <pty.h> (thanks, Kevin) (and I guess
that I have to specify -llibutil at link time - thanks Pete).

Alistair


0 new messages