Does anyone know what the problem might be or what I am doing wrong?
I don't believe it's anything wrong in your two solutions. There's simply no way these could request the behaviour you describe... without deliberately forking a second process (and you don't call
fork()), or killing the
time process, or hacking the kernel etc.
Perhaps your computer is broken.
I might try running
rpm --verify -a in this case. Previously I've had weird behaviour caused by silent disk corruption.
It could also be a bug in the chain of software which displays the output.
If you can reproduce the problem with an input file of a mere 100kB, here's a different computer for you which is almost certainly not corrupted in the same way as the host computer it is run on. Console output is pretty slow, there's only a few megabytes of free space as well. The output from running your program under
time will not match real seconds for some reason, it shouldn't matter for this question though. The clipboard text box doesn't accept keyboard input for me (Firefox 53), so I used the right-click menu to copy data in through
/dev/clipboard as per the FAQ.