March 8th, 2003, 02:39 AM
Attaching threads to read/write from a tty
I understand that all threads within a process share their file descriptors, so I was wondering if it was possible to for each thread within the process to have it's own tty.
What I hope can be accomplished is to spawn off a no. of threads, and for each thread, have it read and write from it's own tty device.
This would mean that I can't dup2() file descriptors and close() stdin/stdout, since that would close() the stdin/stdout for the entire process (and consequently all other threads). How then would I redirect input and output? Would I have to open each tty for read/write and then have each thread read/write to the thread using write(tty_fd, buf, nbyte)?
Thanks for reading this far!
PS. I would like to thank M. Hirsch and Scorpions4ever for helping me out in my last thread "fork a process with a different terminal?"
March 8th, 2003, 10:55 PM
Unfortunately, a thread inherits the parent processes file descriptors as a shared resource, instead of its own copy of it. So closing it will affect all the threads. It's probably a lot easier using write(tty_fd,...);