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 3282956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:59:11+00:00 2026-05-17T19:59:11+00:00

I use the following program to write to a fifo: #include <iostream> #include <fstream>

  • 0

I use the following program to write to a fifo:

#include <iostream>
#include <fstream>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

using namespace std;

int main() {

    unlink("fifo1");

    if (mkfifo("fifo1", 0666) != 0) {
        cout << "Error while creating fifo" << endl;
        return 1;
    }
    else {
        cout << "Fifo created" << endl;
    }

    int fd = open("fifo1", O_WRONLY);
    if(fd == -1) {
        cout << "Could not open file" << endl;
        return 1;
    }
    else {
        cout << "Fifo opened" << endl;
    }


    int i=0;
    char* buffer = new char[20];
    while(true) {
        sprintf(buffer, "look: %i\n", i++);

        int r = write(fd, buffer, strlen(buffer));
        if(r == -1) {
            cout << "Fifo Error:" << fd << endl;
        }
        else {
            cout << "Wrote: " << i << "(" << r << "B)"<< endl;
        }
        sleep(1);
    }

    return 0;
}

If I start this program, start another shell and type there

cat < fifo1

I can see that the program writes something to the pipe and I can see the output in the reading shell. If I stop the cat command with CTRL^C also the FIFO Writer termintes, with no error message. What is the reason for this? Why is no error thrown?

The weird thing is, if I start the above code with Eclipse CDT and the reading shell is closed with CTRL^C the program continues printing “Error: 3”.

Looking forward to your ideas,
heinrich

  • 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-17T19:59:11+00:00Added an answer on May 17, 2026 at 7:59 pm

    If you write to a pipe when the other end of the pipe has been closed a SIGPIPE will be delivered to your process. Without an installed signal handler, this will kill your process immediately. Normally this is output, I don’t know why do do not see this.

    If you rather like to check the error codes of write than get a SIGPIPE as your code suggests, you have to ignore SIGPIPE:

    #include <signal.h>
    
    signal( SIGPIPE, SIG_IGN );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I write the following program: file 1: #include <stdio.h> int global; void print_global1()
I could use the following: <fileset dir=C:\Program Files\eclipse\plugins\myplugin> <include name=extraStuff.jar /> </fileset> But that
Consider the following use of template template parameters... #include <iostream> template <typename X> class
I have the following piece of code in C++: #include <iostream> #include <fstream> #include
I wanted to use boost::thread in my program, but get the following compiler error
Let me use the following example to explain my question: public string ExampleFunction(string Variable)
i have question how write program which calculates following procedures http://en.wikipedia.org/wiki/Tetration i have exponential
I wanted to write a timer in java.which will do the following: when program
I use the following to get a list of project files that need to
I use the following statement prepared and bound in ODBC: SELECT (CASE profile WHEN

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.