Cannot Write in Named Pipe











up vote
0
down vote

favorite












In this code my program crashes in when I am opening the pipe for writing.



char pipe[30];
int fd, tmp = 2;
sprintf(pipe, "root_%d", getpid());
ret_val = mkfifo(pipe, 0666);
fd = open(pipe, O_WRONLY); //HERE IS CRASHING - SUDDENLY FREEZES
write(fd, &tmp, sizeof(int));
close(fd)


All seems good, but where is my mistake;










share|improve this question




















  • 1




    Please post a proper MCVE.
    – Acorn
    Nov 18 at 19:36










  • Please include that stack trace (e.g. from gdb).
    – ShiDoiSi
    Nov 18 at 19:38










  • Add error checking and handling for starters. And what is temp? And what line is your debugger showing the crash on? For that matter, what do you mean by crash?
    – Shawn
    Nov 18 at 19:38










  • Okay I edited it guys
    – NickSt
    Nov 18 at 19:40












  • It's still far from an Minimal, Complete, and Verifiable example. Did you read the link?
    – Broman
    Nov 18 at 19:55

















up vote
0
down vote

favorite












In this code my program crashes in when I am opening the pipe for writing.



char pipe[30];
int fd, tmp = 2;
sprintf(pipe, "root_%d", getpid());
ret_val = mkfifo(pipe, 0666);
fd = open(pipe, O_WRONLY); //HERE IS CRASHING - SUDDENLY FREEZES
write(fd, &tmp, sizeof(int));
close(fd)


All seems good, but where is my mistake;










share|improve this question




















  • 1




    Please post a proper MCVE.
    – Acorn
    Nov 18 at 19:36










  • Please include that stack trace (e.g. from gdb).
    – ShiDoiSi
    Nov 18 at 19:38










  • Add error checking and handling for starters. And what is temp? And what line is your debugger showing the crash on? For that matter, what do you mean by crash?
    – Shawn
    Nov 18 at 19:38










  • Okay I edited it guys
    – NickSt
    Nov 18 at 19:40












  • It's still far from an Minimal, Complete, and Verifiable example. Did you read the link?
    – Broman
    Nov 18 at 19:55















up vote
0
down vote

favorite









up vote
0
down vote

favorite











In this code my program crashes in when I am opening the pipe for writing.



char pipe[30];
int fd, tmp = 2;
sprintf(pipe, "root_%d", getpid());
ret_val = mkfifo(pipe, 0666);
fd = open(pipe, O_WRONLY); //HERE IS CRASHING - SUDDENLY FREEZES
write(fd, &tmp, sizeof(int));
close(fd)


All seems good, but where is my mistake;










share|improve this question















In this code my program crashes in when I am opening the pipe for writing.



char pipe[30];
int fd, tmp = 2;
sprintf(pipe, "root_%d", getpid());
ret_val = mkfifo(pipe, 0666);
fd = open(pipe, O_WRONLY); //HERE IS CRASHING - SUDDENLY FREEZES
write(fd, &tmp, sizeof(int));
close(fd)


All seems good, but where is my mistake;







c pipe mkfifo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 19:40

























asked Nov 18 at 19:31









NickSt

11




11








  • 1




    Please post a proper MCVE.
    – Acorn
    Nov 18 at 19:36










  • Please include that stack trace (e.g. from gdb).
    – ShiDoiSi
    Nov 18 at 19:38










  • Add error checking and handling for starters. And what is temp? And what line is your debugger showing the crash on? For that matter, what do you mean by crash?
    – Shawn
    Nov 18 at 19:38










  • Okay I edited it guys
    – NickSt
    Nov 18 at 19:40












  • It's still far from an Minimal, Complete, and Verifiable example. Did you read the link?
    – Broman
    Nov 18 at 19:55
















  • 1




    Please post a proper MCVE.
    – Acorn
    Nov 18 at 19:36










  • Please include that stack trace (e.g. from gdb).
    – ShiDoiSi
    Nov 18 at 19:38










  • Add error checking and handling for starters. And what is temp? And what line is your debugger showing the crash on? For that matter, what do you mean by crash?
    – Shawn
    Nov 18 at 19:38










  • Okay I edited it guys
    – NickSt
    Nov 18 at 19:40












  • It's still far from an Minimal, Complete, and Verifiable example. Did you read the link?
    – Broman
    Nov 18 at 19:55










1




1




Please post a proper MCVE.
– Acorn
Nov 18 at 19:36




Please post a proper MCVE.
– Acorn
Nov 18 at 19:36












Please include that stack trace (e.g. from gdb).
– ShiDoiSi
Nov 18 at 19:38




Please include that stack trace (e.g. from gdb).
– ShiDoiSi
Nov 18 at 19:38












Add error checking and handling for starters. And what is temp? And what line is your debugger showing the crash on? For that matter, what do you mean by crash?
– Shawn
Nov 18 at 19:38




Add error checking and handling for starters. And what is temp? And what line is your debugger showing the crash on? For that matter, what do you mean by crash?
– Shawn
Nov 18 at 19:38












Okay I edited it guys
– NickSt
Nov 18 at 19:40






Okay I edited it guys
– NickSt
Nov 18 at 19:40














It's still far from an Minimal, Complete, and Verifiable example. Did you read the link?
– Broman
Nov 18 at 19:55






It's still far from an Minimal, Complete, and Verifiable example. Did you read the link?
– Broman
Nov 18 at 19:55














1 Answer
1






active

oldest

votes

















up vote
1
down vote













It is an expected behavior. From man 7 fifo:




Normally, opening the FIFO blocks until the other end is opened also.




So your open does not return until somebody opens the same pipe for reading. You may want to add O_NONBLOCK flag (and likely get SIGPIPE on writing), or revisit the design.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364690%2fcannot-write-in-named-pipe%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    It is an expected behavior. From man 7 fifo:




    Normally, opening the FIFO blocks until the other end is opened also.




    So your open does not return until somebody opens the same pipe for reading. You may want to add O_NONBLOCK flag (and likely get SIGPIPE on writing), or revisit the design.






    share|improve this answer

























      up vote
      1
      down vote













      It is an expected behavior. From man 7 fifo:




      Normally, opening the FIFO blocks until the other end is opened also.




      So your open does not return until somebody opens the same pipe for reading. You may want to add O_NONBLOCK flag (and likely get SIGPIPE on writing), or revisit the design.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        It is an expected behavior. From man 7 fifo:




        Normally, opening the FIFO blocks until the other end is opened also.




        So your open does not return until somebody opens the same pipe for reading. You may want to add O_NONBLOCK flag (and likely get SIGPIPE on writing), or revisit the design.






        share|improve this answer












        It is an expected behavior. From man 7 fifo:




        Normally, opening the FIFO blocks until the other end is opened also.




        So your open does not return until somebody opens the same pipe for reading. You may want to add O_NONBLOCK flag (and likely get SIGPIPE on writing), or revisit the design.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 at 20:08









        user58697

        4,0831717




        4,0831717






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364690%2fcannot-write-in-named-pipe%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin