ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I just happen to make my pipes non-blocking, so following code I do use to make it non-blocking would be:
Code:
int fl;
/* RECEIVE side of the pipe */
fcntl(pipe_desc[0], F_GETFL, &fl);
fcntl(pipe_desc[0], F_SETFL, (fl | O_NONBLOCK));
/* TRANSMIT side of the pipe */
fcntl(pipe_desc[1], F_GETFL, &fl);
fcntl(pipe_desc[1], F_SETFL, (fl | O_NONBLOCK));
I long ago wrote a blog entry on this subject, feel free to review, it is located here.
Where have you used the pipe2() function? It's not in that code. Why not read the recommendations to use [code] tags for one, and then secondly why not look at the 5 or 6 lines of sample code I posted and realize that this does exactly what you intend.
You are not using pipe() or pipe2() at all. Please review the man page. Why not give the blog entry a read too. There are code examples and there are additional blog entries to illustrate more complex things like how to use select() when you have multiple descriptors to check for inbound data.
I realize that persons like to do things their selves and thus feel they've learned better that way.
I myself learned these things by emulation, by searching for code examples, then doing experimentations much like you are, and then improving upon them.
But what I'm telling you is that while you are on the cusp of working with the concept of pipes, you are not actually correctly working with pipes in the classical Unix/Linux sense.
I believe my original experimentations were guided by the results of a web search where I used terms like "pipe programming example linux c" and I probably allowed the auto-complete to give me alternate suggestions.
The two main concepts to start with are (1) how to create a pipe at all, and then (2) how to use it. The next level of step is how to configure it. You say you want non-blocking I/O and I've told you that a natively created pipe is non-blocking I/O.
Once again, I'm not angry here, but what you're doing is making a case for the continual divisiveness between questioners and the offerers of answers. You'll get frustrated, because you've put in some effort, it's not correct, so you've been given some other recommendations, valid ones, and also not too complicated ones, and it appears that you're ignoring those things completely, as well as the points related to using [code] tags. We get frustrated seeing yet another questioner who ignores our suggestions, so we back off and figure, "Why bother? They're not reading what we write."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.