Linux FIFO buffering depends on invocation order of readers and writerscontinuous reading from named pipe...
GPLv3 forces us to make code available, but to who?
Can I cast Death Ward on additional creatures without causing previous castings to end?
Why do Russians sometimes spell "жирный" (fatty) as "жырный"?
Is there an in-universe explanation of how Frodo's arrival in Valinor was recorded in the Red Book?
Why does `FindFit` fail so badly in this simple case?
How to find places to store/land a private airplane?
Do jackscrews suffer from blowdown?
What are one's options when facing religious discrimination at the airport?
Can a passenger predict that an airline or a tour operator is about to go bankrupt?
Could the Queen overturn the UK Supreme Court ruling regarding prorogation of Parliament?
Decision Variable Value from a Set (Gurobi)
A word that refers to saying something in an attempt to anger or embarrass someone into doing something that they don’t want to do?
How to "Start as close to the end as possible", and why to do so?
Can I bring this power bank on board the aircraft?
Does the US Armed Forces refuse to recruit anyone with an IQ less than 83?
Giving a good fancy look to a simple table
Sending mail to the Professor for PhD, after seeing his tweet
Drawing Maps; flat distortion
If I travelled back in time to invest in X company to make a fortune, roughly what is the probability that it would fail?
French license plates
Did the Soviet army intentionally send troops (e.g. penal battalions) running over minefields?
Why such a singular place for bird watching?
Booting Ubuntu from USB drive on MSI motherboard -- EVERYTHING fails
Realistically, how much do you need to start investing?
Linux FIFO buffering depends on invocation order of readers and writers
continuous reading from named pipe (cat or tail -f)How to read from two input files using while loop(SOLVED) How I get the current working directory with inverted slash?Avoiding Buffering With Output RedirectionWriting a Unix shell script to call a C function and redirecting data to a .txt file`tail -f` consumes last line partially, doesn't care about newlines or nulBreak out of while-read statementCommands leaking characters to bash
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}
I'm trying to write a simple python script that reads from a fifo and then writes to another fifo.
I have created two FIFOs using the following command:
$ mkfifo input
$ mkfifo output
I invoke the script using the following command:
$ tail -f input | stdbuf -oL ../entropyCalc/entropy.py > output
, observe the FIFO output
using:
$ tail -f output
and then invoke a writer using the following command:
$ echo "/path/to/a/valid/file" >> input
The problem is I expect the fifo to output the result as soon as it processes the input file, but I only observe that when I invoke (execute) the script once, exit and then re-execute the script. Everything works fine after this.
In summary:
I don't see any output in the reader if I execute script -> spin up reader -> write to input
fifo
But, the command tail -f output
outputs the result when I execute the script -> spin up the reader -> write to fifo -> kill script -> re-execute the script
I'm not sure what causes this behaviour since I'd expect the system to write to the files as soon as the result is written to stdout. I'd have expected the buffering if I would not used stdbuf -oL
which limits buffering to a line.
The python script is a simple entropy calculator:
#! /usr/bin/env python2
import sys, os
import numpy as np
from scipy.stats import entropy
while 1:
try:
line = sys.stdin.readline()
except KeyboardInterrupt:
break
if not line:
break
line = line.strip()
if not line == '':
fname1 = open(line)
fsize = os.path.getsize(line)
f1 = np.frombuffer(fname1.read(fsize), dtype=np.uint8)
value,counts = np.unique(f1, return_counts=True)
print line,str(entropy(counts))
sys.stdout.flush()
I'm using bash 4.4 on Ubuntu 18.04.3
linux bash ubuntu pipe fifo
add a comment
|
I'm trying to write a simple python script that reads from a fifo and then writes to another fifo.
I have created two FIFOs using the following command:
$ mkfifo input
$ mkfifo output
I invoke the script using the following command:
$ tail -f input | stdbuf -oL ../entropyCalc/entropy.py > output
, observe the FIFO output
using:
$ tail -f output
and then invoke a writer using the following command:
$ echo "/path/to/a/valid/file" >> input
The problem is I expect the fifo to output the result as soon as it processes the input file, but I only observe that when I invoke (execute) the script once, exit and then re-execute the script. Everything works fine after this.
In summary:
I don't see any output in the reader if I execute script -> spin up reader -> write to input
fifo
But, the command tail -f output
outputs the result when I execute the script -> spin up the reader -> write to fifo -> kill script -> re-execute the script
I'm not sure what causes this behaviour since I'd expect the system to write to the files as soon as the result is written to stdout. I'd have expected the buffering if I would not used stdbuf -oL
which limits buffering to a line.
The python script is a simple entropy calculator:
#! /usr/bin/env python2
import sys, os
import numpy as np
from scipy.stats import entropy
while 1:
try:
line = sys.stdin.readline()
except KeyboardInterrupt:
break
if not line:
break
line = line.strip()
if not line == '':
fname1 = open(line)
fsize = os.path.getsize(line)
f1 = np.frombuffer(fname1.read(fsize), dtype=np.uint8)
value,counts = np.unique(f1, return_counts=True)
print line,str(entropy(counts))
sys.stdout.flush()
I'm using bash 4.4 on Ubuntu 18.04.3
linux bash ubuntu pipe fifo
You have unbuffered the script but not tail. Why not? unix.stackexchange.com/a/423645/70524
– muru
4 mins ago
add a comment
|
I'm trying to write a simple python script that reads from a fifo and then writes to another fifo.
I have created two FIFOs using the following command:
$ mkfifo input
$ mkfifo output
I invoke the script using the following command:
$ tail -f input | stdbuf -oL ../entropyCalc/entropy.py > output
, observe the FIFO output
using:
$ tail -f output
and then invoke a writer using the following command:
$ echo "/path/to/a/valid/file" >> input
The problem is I expect the fifo to output the result as soon as it processes the input file, but I only observe that when I invoke (execute) the script once, exit and then re-execute the script. Everything works fine after this.
In summary:
I don't see any output in the reader if I execute script -> spin up reader -> write to input
fifo
But, the command tail -f output
outputs the result when I execute the script -> spin up the reader -> write to fifo -> kill script -> re-execute the script
I'm not sure what causes this behaviour since I'd expect the system to write to the files as soon as the result is written to stdout. I'd have expected the buffering if I would not used stdbuf -oL
which limits buffering to a line.
The python script is a simple entropy calculator:
#! /usr/bin/env python2
import sys, os
import numpy as np
from scipy.stats import entropy
while 1:
try:
line = sys.stdin.readline()
except KeyboardInterrupt:
break
if not line:
break
line = line.strip()
if not line == '':
fname1 = open(line)
fsize = os.path.getsize(line)
f1 = np.frombuffer(fname1.read(fsize), dtype=np.uint8)
value,counts = np.unique(f1, return_counts=True)
print line,str(entropy(counts))
sys.stdout.flush()
I'm using bash 4.4 on Ubuntu 18.04.3
linux bash ubuntu pipe fifo
I'm trying to write a simple python script that reads from a fifo and then writes to another fifo.
I have created two FIFOs using the following command:
$ mkfifo input
$ mkfifo output
I invoke the script using the following command:
$ tail -f input | stdbuf -oL ../entropyCalc/entropy.py > output
, observe the FIFO output
using:
$ tail -f output
and then invoke a writer using the following command:
$ echo "/path/to/a/valid/file" >> input
The problem is I expect the fifo to output the result as soon as it processes the input file, but I only observe that when I invoke (execute) the script once, exit and then re-execute the script. Everything works fine after this.
In summary:
I don't see any output in the reader if I execute script -> spin up reader -> write to input
fifo
But, the command tail -f output
outputs the result when I execute the script -> spin up the reader -> write to fifo -> kill script -> re-execute the script
I'm not sure what causes this behaviour since I'd expect the system to write to the files as soon as the result is written to stdout. I'd have expected the buffering if I would not used stdbuf -oL
which limits buffering to a line.
The python script is a simple entropy calculator:
#! /usr/bin/env python2
import sys, os
import numpy as np
from scipy.stats import entropy
while 1:
try:
line = sys.stdin.readline()
except KeyboardInterrupt:
break
if not line:
break
line = line.strip()
if not line == '':
fname1 = open(line)
fsize = os.path.getsize(line)
f1 = np.frombuffer(fname1.read(fsize), dtype=np.uint8)
value,counts = np.unique(f1, return_counts=True)
print line,str(entropy(counts))
sys.stdout.flush()
I'm using bash 4.4 on Ubuntu 18.04.3
linux bash ubuntu pipe fifo
linux bash ubuntu pipe fifo
edited 10 mins ago
lol
asked 41 mins ago
lollol
236 bronze badges
236 bronze badges
You have unbuffered the script but not tail. Why not? unix.stackexchange.com/a/423645/70524
– muru
4 mins ago
add a comment
|
You have unbuffered the script but not tail. Why not? unix.stackexchange.com/a/423645/70524
– muru
4 mins ago
You have unbuffered the script but not tail. Why not? unix.stackexchange.com/a/423645/70524
– muru
4 mins ago
You have unbuffered the script but not tail. Why not? unix.stackexchange.com/a/423645/70524
– muru
4 mins ago
add a comment
|
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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/4.0/"u003ecc by-sa 4.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
});
}
});
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%2funix.stackexchange.com%2fquestions%2f543767%2flinux-fifo-buffering-depends-on-invocation-order-of-readers-and-writers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2funix.stackexchange.com%2fquestions%2f543767%2flinux-fifo-buffering-depends-on-invocation-order-of-readers-and-writers%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
You have unbuffered the script but not tail. Why not? unix.stackexchange.com/a/423645/70524
– muru
4 mins ago