Discuss Attaching threads to read/write from a tty in the C Programming forum on Dev Shed. Attaching threads to read/write from a tty C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Time spent in forums: < 1 sec
Reputation Power: 12
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)?
Location: Woodland Hills, Los Angeles County, California, USA
Time spent in forums: 2 Months 3 Days 6 h 2 m 28 sec
Reputation Power: 4106
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,...);