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

Let say I have the following desire, to simplify the IConvertible's to allow me
I need to solve the following question which i can't get to work by
My question is about memory use and objects in actionscript 2. If I have
I want to use a temp directory that will be unique to this build.
(please excuse that I didn't use aliases). I would like my query output to
I make a distributed embedded application that will make use of several micro-controllers. The
I need to develop a file indexing application in python and wanted to know
I am learning on my own about writing an interpreter for a programming language,
I have a new web app that is packaged as a WAR as part
We manage a site for a medical charity. They have a number of links

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.