Can someone explain what is going on please?
Both processes share the same filehandle file descriptor, plus the libc usually reads ahead. If /etc/passwd is small enough, the libc slurps the entire file in one process during the first getline(), leaving nothing for the other process.
Quoting from the linux man page of fork(2):
The child inherits copies of the parent's set of open file descriptors. Each file descriptor in the child refers to the same open file description (see open(2)) as the corresponding file descriptor in the parent. This means that the two descriptors share open file status flags, current file offset, and signal-driven I/O attributes (see the description of F_SETOWN and F_SETSIG in fcntl(2)).
Alexander
In reply to Re: confusing fork/readline behaviour
by afoken
in thread confusing fork/readline behaviour
by flipper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |