What probability distribution models this race condition?
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
Consider the following command:bash -c "echo x; cat 1" | tee 1
.
My understanding is that it would fork to a new shell, write x
to stdout, write file 1 not found
to stderr, exit and return control to the parent process, and write x
to stdout and to 1
. Hence, I would expect the final output to be x
, and the file 1
contains exactly the string x
.
However, this is not the case. In actuality, the file 1
usually contains at least two instances of x
, and sometimes thousands of lines of x
s. On a batch test of running the command ten thousand times, the mean number of x
s written to the file was 52.3, and the median was 1. What mechanic is causing this? What probability distribution models this behavior? I suspect that it is conditionally geometric and otherwise uniform.
shell files pipe
add a comment |Â
up vote
5
down vote
favorite
Consider the following command:bash -c "echo x; cat 1" | tee 1
.
My understanding is that it would fork to a new shell, write x
to stdout, write file 1 not found
to stderr, exit and return control to the parent process, and write x
to stdout and to 1
. Hence, I would expect the final output to be x
, and the file 1
contains exactly the string x
.
However, this is not the case. In actuality, the file 1
usually contains at least two instances of x
, and sometimes thousands of lines of x
s. On a batch test of running the command ten thousand times, the mean number of x
s written to the file was 52.3, and the median was 1. What mechanic is causing this? What probability distribution models this behavior? I suspect that it is conditionally geometric and otherwise uniform.
shell files pipe
3
It has to do with the timing of the execution of the left and right hand side of the pipeline. Both are started simultaneously, or close to it. Iftee
has opened the file for writing beforecat
opens it for reading, you may get manyx
-es in the file. In that case, the "loop" would end whenevercat
reads faster thantee
writes, reaching the end of the file.
â Kusalananda
Aug 10 at 18:42
From limited testing here, the average number ofx
s written to the file was of 4.35. I guess it will depends a lot on machine load.
â Renan
Aug 11 at 0:18
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
Consider the following command:bash -c "echo x; cat 1" | tee 1
.
My understanding is that it would fork to a new shell, write x
to stdout, write file 1 not found
to stderr, exit and return control to the parent process, and write x
to stdout and to 1
. Hence, I would expect the final output to be x
, and the file 1
contains exactly the string x
.
However, this is not the case. In actuality, the file 1
usually contains at least two instances of x
, and sometimes thousands of lines of x
s. On a batch test of running the command ten thousand times, the mean number of x
s written to the file was 52.3, and the median was 1. What mechanic is causing this? What probability distribution models this behavior? I suspect that it is conditionally geometric and otherwise uniform.
shell files pipe
Consider the following command:bash -c "echo x; cat 1" | tee 1
.
My understanding is that it would fork to a new shell, write x
to stdout, write file 1 not found
to stderr, exit and return control to the parent process, and write x
to stdout and to 1
. Hence, I would expect the final output to be x
, and the file 1
contains exactly the string x
.
However, this is not the case. In actuality, the file 1
usually contains at least two instances of x
, and sometimes thousands of lines of x
s. On a batch test of running the command ten thousand times, the mean number of x
s written to the file was 52.3, and the median was 1. What mechanic is causing this? What probability distribution models this behavior? I suspect that it is conditionally geometric and otherwise uniform.
shell files pipe
shell files pipe
asked Aug 10 at 18:39
Will Sherwood
1261
1261
3
It has to do with the timing of the execution of the left and right hand side of the pipeline. Both are started simultaneously, or close to it. Iftee
has opened the file for writing beforecat
opens it for reading, you may get manyx
-es in the file. In that case, the "loop" would end whenevercat
reads faster thantee
writes, reaching the end of the file.
â Kusalananda
Aug 10 at 18:42
From limited testing here, the average number ofx
s written to the file was of 4.35. I guess it will depends a lot on machine load.
â Renan
Aug 11 at 0:18
add a comment |Â
3
It has to do with the timing of the execution of the left and right hand side of the pipeline. Both are started simultaneously, or close to it. Iftee
has opened the file for writing beforecat
opens it for reading, you may get manyx
-es in the file. In that case, the "loop" would end whenevercat
reads faster thantee
writes, reaching the end of the file.
â Kusalananda
Aug 10 at 18:42
From limited testing here, the average number ofx
s written to the file was of 4.35. I guess it will depends a lot on machine load.
â Renan
Aug 11 at 0:18
3
3
It has to do with the timing of the execution of the left and right hand side of the pipeline. Both are started simultaneously, or close to it. If
tee
has opened the file for writing before cat
opens it for reading, you may get many x
-es in the file. In that case, the "loop" would end whenever cat
reads faster than tee
writes, reaching the end of the file.â Kusalananda
Aug 10 at 18:42
It has to do with the timing of the execution of the left and right hand side of the pipeline. Both are started simultaneously, or close to it. If
tee
has opened the file for writing before cat
opens it for reading, you may get many x
-es in the file. In that case, the "loop" would end whenever cat
reads faster than tee
writes, reaching the end of the file.â Kusalananda
Aug 10 at 18:42
From limited testing here, the average number of
x
s written to the file was of 4.35. I guess it will depends a lot on machine load.â Renan
Aug 11 at 0:18
From limited testing here, the average number of
x
s written to the file was of 4.35. I guess it will depends a lot on machine load.â Renan
Aug 11 at 0:18
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%2f461878%2fwhat-probability-distribution-models-this-race-condition%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
3
It has to do with the timing of the execution of the left and right hand side of the pipeline. Both are started simultaneously, or close to it. If
tee
has opened the file for writing beforecat
opens it for reading, you may get manyx
-es in the file. In that case, the "loop" would end whenevercat
reads faster thantee
writes, reaching the end of the file.â Kusalananda
Aug 10 at 18:42
From limited testing here, the average number of
x
s written to the file was of 4.35. I guess it will depends a lot on machine load.â Renan
Aug 11 at 0:18