Retaining data in a named pipe after an incomplete read access

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
Prerequisites:
$ mkfifo pipe1
If several lines are put into pipe1
$ (echo line 1; echo line 2) > pipe1
all the lines can be read in another terminal by
$ cat pipe1
line 1
line 2
So far all right.
But
if instead of the latter cat several partial reads are executed
$ head -n 1 pipe1; head -n 1 pipe1
line 1
then only the first line of the data piped into pipe1 is returned (by the first head -n 1); the rest of the data seems to get lost, the second read access is hanging hence waiting for (new) data available in pipe1.
How
to set up a named pipe and pipe contents to it in such a way that several consecutive partial reads are possible?
In other words, how to get this:
$ head -n 1 pipe1; head -n 1 pipe1
line 1
line 2
io-redirection fifo
add a comment |Â
up vote
1
down vote
favorite
Prerequisites:
$ mkfifo pipe1
If several lines are put into pipe1
$ (echo line 1; echo line 2) > pipe1
all the lines can be read in another terminal by
$ cat pipe1
line 1
line 2
So far all right.
But
if instead of the latter cat several partial reads are executed
$ head -n 1 pipe1; head -n 1 pipe1
line 1
then only the first line of the data piped into pipe1 is returned (by the first head -n 1); the rest of the data seems to get lost, the second read access is hanging hence waiting for (new) data available in pipe1.
How
to set up a named pipe and pipe contents to it in such a way that several consecutive partial reads are possible?
In other words, how to get this:
$ head -n 1 pipe1; head -n 1 pipe1
line 1
line 2
io-redirection fifo
IIRC, but I may be wrong here, you can't close the pipe - this will flush the data. Butheadcloses it. So you'll need a custom version ofheadthat doesn't close it. Not very elegant. What are you trying to achieve with this? It sounds like an XY-Problem.
â dirkt
Jul 20 at 13:11
@dirk1 In the end I want to have a persistent FIFO queue: write arbitrary times to a file, read arbitrary times from the same file, data that is read disappears from the queue. Named pipes seemed to me like a solution for that. But as pointed out in the question, it does not work like expected by me.
â Min-Soo Pipefeet
Jul 20 at 13:18
Pipes won't work for this. See e.g. here for alternatives.
â dirkt
Jul 20 at 14:29
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Prerequisites:
$ mkfifo pipe1
If several lines are put into pipe1
$ (echo line 1; echo line 2) > pipe1
all the lines can be read in another terminal by
$ cat pipe1
line 1
line 2
So far all right.
But
if instead of the latter cat several partial reads are executed
$ head -n 1 pipe1; head -n 1 pipe1
line 1
then only the first line of the data piped into pipe1 is returned (by the first head -n 1); the rest of the data seems to get lost, the second read access is hanging hence waiting for (new) data available in pipe1.
How
to set up a named pipe and pipe contents to it in such a way that several consecutive partial reads are possible?
In other words, how to get this:
$ head -n 1 pipe1; head -n 1 pipe1
line 1
line 2
io-redirection fifo
Prerequisites:
$ mkfifo pipe1
If several lines are put into pipe1
$ (echo line 1; echo line 2) > pipe1
all the lines can be read in another terminal by
$ cat pipe1
line 1
line 2
So far all right.
But
if instead of the latter cat several partial reads are executed
$ head -n 1 pipe1; head -n 1 pipe1
line 1
then only the first line of the data piped into pipe1 is returned (by the first head -n 1); the rest of the data seems to get lost, the second read access is hanging hence waiting for (new) data available in pipe1.
How
to set up a named pipe and pipe contents to it in such a way that several consecutive partial reads are possible?
In other words, how to get this:
$ head -n 1 pipe1; head -n 1 pipe1
line 1
line 2
io-redirection fifo
edited Jul 20 at 13:11
asked Jul 20 at 13:07
Min-Soo Pipefeet
1064
1064
IIRC, but I may be wrong here, you can't close the pipe - this will flush the data. Butheadcloses it. So you'll need a custom version ofheadthat doesn't close it. Not very elegant. What are you trying to achieve with this? It sounds like an XY-Problem.
â dirkt
Jul 20 at 13:11
@dirk1 In the end I want to have a persistent FIFO queue: write arbitrary times to a file, read arbitrary times from the same file, data that is read disappears from the queue. Named pipes seemed to me like a solution for that. But as pointed out in the question, it does not work like expected by me.
â Min-Soo Pipefeet
Jul 20 at 13:18
Pipes won't work for this. See e.g. here for alternatives.
â dirkt
Jul 20 at 14:29
add a comment |Â
IIRC, but I may be wrong here, you can't close the pipe - this will flush the data. Butheadcloses it. So you'll need a custom version ofheadthat doesn't close it. Not very elegant. What are you trying to achieve with this? It sounds like an XY-Problem.
â dirkt
Jul 20 at 13:11
@dirk1 In the end I want to have a persistent FIFO queue: write arbitrary times to a file, read arbitrary times from the same file, data that is read disappears from the queue. Named pipes seemed to me like a solution for that. But as pointed out in the question, it does not work like expected by me.
â Min-Soo Pipefeet
Jul 20 at 13:18
Pipes won't work for this. See e.g. here for alternatives.
â dirkt
Jul 20 at 14:29
IIRC, but I may be wrong here, you can't close the pipe - this will flush the data. But
head closes it. So you'll need a custom version of head that doesn't close it. Not very elegant. What are you trying to achieve with this? It sounds like an XY-Problem.â dirkt
Jul 20 at 13:11
IIRC, but I may be wrong here, you can't close the pipe - this will flush the data. But
head closes it. So you'll need a custom version of head that doesn't close it. Not very elegant. What are you trying to achieve with this? It sounds like an XY-Problem.â dirkt
Jul 20 at 13:11
@dirk1 In the end I want to have a persistent FIFO queue: write arbitrary times to a file, read arbitrary times from the same file, data that is read disappears from the queue. Named pipes seemed to me like a solution for that. But as pointed out in the question, it does not work like expected by me.
â Min-Soo Pipefeet
Jul 20 at 13:18
@dirk1 In the end I want to have a persistent FIFO queue: write arbitrary times to a file, read arbitrary times from the same file, data that is read disappears from the queue. Named pipes seemed to me like a solution for that. But as pointed out in the question, it does not work like expected by me.
â Min-Soo Pipefeet
Jul 20 at 13:18
Pipes won't work for this. See e.g. here for alternatives.
â dirkt
Jul 20 at 14:29
Pipes won't work for this. See e.g. here for alternatives.
â dirkt
Jul 20 at 14:29
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457444%2fretaining-data-in-a-named-pipe-after-an-incomplete-read-access%23new-answer', 'question_page');
);
Post as a guest
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
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
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
IIRC, but I may be wrong here, you can't close the pipe - this will flush the data. But
headcloses it. So you'll need a custom version ofheadthat doesn't close it. Not very elegant. What are you trying to achieve with this? It sounds like an XY-Problem.â dirkt
Jul 20 at 13:11
@dirk1 In the end I want to have a persistent FIFO queue: write arbitrary times to a file, read arbitrary times from the same file, data that is read disappears from the queue. Named pipes seemed to me like a solution for that. But as pointed out in the question, it does not work like expected by me.
â Min-Soo Pipefeet
Jul 20 at 13:18
Pipes won't work for this. See e.g. here for alternatives.
â dirkt
Jul 20 at 14:29