It depends on the OS buffers and the timing between the 10th and 11th writes of dmesg
.
After head
writes 10 lines, it terminates and dmesg
will receive SIGPIPE signal if it continues writing to the pipe.
Depending on your OS buffer, dmesg
will often write more than 10 lines before head
consumes them.
To see that head
had consumed more than 10 lines, you can use:
strace -f sh -c 'dmesg | head -n 10'
(Look at the head
process, count on number of read
system calls.)
To see how the writing speed effect:
strace -f sh -c "perl -le '$|++;print 1 while 1' | head -n 10"
dmesg
was killed after 10 lines. – cuonglm Jan 18 '16 at 10:57dmesg
receives EPIPE, just as described in the duplicate answer. – Chris Davies Jan 19 '16 at 17:42