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;
c pipe mkfifo
add a comment |
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;
c pipe mkfifo
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 istemp
? 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
add a comment |
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;
c pipe mkfifo
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
c pipe mkfifo
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 istemp
? 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
add a comment |
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 istemp
? 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
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 18 at 20:08
user58697
4,0831717
4,0831717
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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