Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1002623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:51:25+00:00 2026-05-16T07:51:25+00:00

Having more than one process read from a serial device (/dev/ttyXX) makes it so

  • 0

Having more than one process read from a serial device (/dev/ttyXX) makes it so that both processes can’t get all of the data — the data will be split between them in some way. I’d like to write a program that reads from a serial device, creates several master/slave pty pairs, and then allows programs that were made to read from the serial device to instead read from the ptys so that all reading processes receive the data from the serial device and have the ptys act like the serial device in the sense that when they start reading from the pty they get only the most recent data. In other words, you won’t get any data that was written before you started to read (it’s my experience that this is how /dev/ttyXX devices work, or at least the RS-232 anemometer I’m reading from). Named pipes can mimic these semantics by trapping SIGPIPE to determine that there is no reader and thus we can choose not to write to that particular named pipe. However, some binaries that were written to use terminals may fail when talking to named pipes, as checks for isatty() and the errno condition on calls like tcsetattr() can cause failing conditions. The key here is to be able to use existing binaries that were written for a terminal.

So, if I can detect when the slave side of the pty is opened for reading, this should give me roughly the same semantics as there being no SIGPIPE in the named pipe case. I notice that HP-UX has TIOCTRAP as an ioctl() command which seems to do exactly what I want, but sadly it is not available on Linux.

I’ve been reading references for days and the number of options for this type of thing is staggering. The answer might lie in the terminal settings, blocking/non-blocking behavior, setting buffer sizes somewhere, conditions reported from poll()/select(), or some combination. I can’t seem to find anything, though. I’m wondering if it’s possible that I need to write my own device driver, but it seems like I should be able to do this without going that far.

So, for clarification:
– The question is: How can I detect when someone opens the slave side of a pty (pseudo-terminal) in Linux?
– I want a reader opening the slave side of the pty to receive data written strictly after the reader opens the pty (if my multi-writing process just writes data for a while before the reader opens the slave side, the data will buffer up and eventually the writer will block and the slave reader, upon opening, will immediately get all the buffered data — this is not desirable as I want it to get only data generated in the immediate temporal vicinity)

– It must be a pty, not a named pipe, socket, etc, as isatty() and tcsetattr(), etc need to be OK so that existing binaries work

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:51:26+00:00Added an answer on May 16, 2026 at 7:51 am

    The reason you can’t find this is because there’s no documented interface specifically to allow it. However, there is a trick that allows you to do it. After opening the pseudo-terminal master (assumed here to be file descriptor ptm), you open and immediately close the slave side:

    close(open(ptsname(ptm), O_RDWR | O_NOCTTY));
    

    This sets the HUP flag on the tty master. You now poll the HUP flag regularly with poll() (say, whenever data comes in from your data source):

    struct pollfd pfd = { .fd = ptm, .events = POLLHUP };
    poll(&pfd, 1, 10 /* or other small timeout */);
    
    if (!(pfd.revents & POLLHUP))
    {
        /* There is now a reader on the slave side */
    }
    

    If the reader ever goes away, POLLHUP will be set again.

    In your case, you probably don’t even need to remember from one loop to the next whether a given pty has a reader – just block on read() on your data source, then when data is available, simultaneously poll() all of your master ttys and send the data to any of them that do not have POLLHUP set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Take a look at http://vimdoc.sourceforge.net/htmldoc/insert.html There are a few more… May 16, 2026 at 12:42 pm
  • Editorial Team
    Editorial Team added an answer by default Spring-WS 1.5.x uses org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter which uses org.springframework.ws.transport.http.HttpServletConnection to… May 16, 2026 at 12:42 pm
  • Editorial Team
    Editorial Team added an answer Do you mean, can a constraint also be put on… May 16, 2026 at 12:42 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I've heard more than one person say that if your build process is clicking
How will i have a form having more than one submit buttons ..? And
No worries! It looks more complex than it actually is! Just get down to
Having a problem with parsing Snort logs using the pyparsing module. The problem is
I'm having trouble distinguishing the practical difference between calling glFlush() and glFinish() . The
I’m having some trouble with understanding how IIS is handling static variables on its
I'm building a processing pipeline with NServiceBus but I'm having trouble with the configuration
I've got a Subversion repository that our Atlassian Fisheye instances nearly chokes on because
Im having trouble getting my head round subqueries in Mysql. Fairly simple ones are
I am upgrading my Rails plugin to be an engine that works with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.