I looked at simple fork code and decided to try it myself. I compiled and then ran it from inside Emacs and got a different output for this output obtained when I ran it in Bash.
#include <unistd.h> #include <stdio.h> int main() { if (fork() != 0) { printf("%d: X\n", getpid()); } if (fork() != 0) { printf("%d: Y\n", getpid()); } printf("%d: Z\n", getpid()); }
I compiled it with gcc and then ran a.out from inside Emacs and also connected it to cat and grep . and got it.
2055: X
2055: Y
2055: Z
2055: X
2058: Z
2057: Y
2057: Z
2059: Z
It is not right. Performing it only with Bash, I get (what I expected)
2084: X
2084: Y
2084: Z
2085: Y
2085: Z
2087: Z
2086: Z
edit - skipped several lines of a new line
What's happening?
c linux bash pipe fork
Squidly
source share