Situation:
Processes A->B->C

A is my executable
B is a process forked by A, then replaced for KDE Konsole, gnome-terminal, xterm or some other via exec()
C is bash/sh or whatever the pseudo terminal started

There should be now master/slave pseudo TTY link working between B,C. On my computer Konsole seems to hold both /dev/ptmx AND the slave /dev/pts/X. bash has only the slave open.

On xterm/bash combination, xterm has only the master device open and bash has the slave. I don't have gnome installed, but assume it's much like above. So this far all good.

Problem:
I need to open the slave device in process A so that I can write to the second terminal... but can't figure what's the best way to do that. The goal is to create more terminal windows for ncurses (newterm(..) instead of initscr())!

What I did think was to iterate all devices in /dev/pts/ but then I don't know which one is linked to the terminal.

I could also list the open file descriptors in /proc/<pid of B or C>/fd/ and use them somehow; One way that might actually work is to look for open fd of C in /proc that has number 0,1 or 2 and then extract the corresponding device path. But is there better way to do that than by parsing file names? Are there any system/library calls that do this sort of thing?

I'm quite new in this ipc/fd/dev/ioctl/fork stuff

Any advices ?