Pseudo Terminals

I need to spawn a number of foreground process by reading a configuration file. Each process needs some form of I/O. Hence I need to run it on different terminals.
How it can be done programatically , i.e. , my module needs to find which terminal is not in use, then open it, execute the process and set the terminal as its controlling terminal.

I am working on SunOS el 5.8

You will want to use STREAMS based pty's with any new code. Here is an example of how to do that. (Scroll down until you see ptmx which will be highlighted.)

Another option is to use the old BSD pty's which are documented on pty(8). The trick there is to open, in sequence, each master device until one finally succeeds. When one of the opens finally work, you have allocated that pty. As the number of pty's grows, this takes longer and longer.

I wonder how virtual terminals work asynchronously. When the system boots (SCO 3.2v5.0.5) we are prompted by at least twelve terminals (provided they are all enabled). We can work on any of them by pressing the key combination in series ALT + FUNC KEY NO for the respective tty terminals. Now which driver is actually capturing these keys and how it is restoring the previous stored screen and interfaces with the user? How can we implement this type of same concept?