#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    32
    Rep Power
    13

    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?"
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,645
    Rep Power
    4248
    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,...);

IMN logo majestic logo threadwatch logo seochat tools logo