coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does head util cause SIGPIPE?


From: Ray Satiro
Subject: Does head util cause SIGPIPE?
Date: Fri, 25 Oct 2019 03:56:49 -0400
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0

Recently I tracked down a delay in some scripts to this line:

find / -name filename* 2>/dev/null | head -n 1

It appeared that the searching continued after the first result was found. I expected head would terminate and SIGPIPE would be sent which would cause find to terminate, but that did not happen. Since I was in cygwin I thought maybe it was a Windows issue but I tried in Ubuntu 16 with an aribtrary file and noticed the same thing. I also tried disabling any pipe trap and monitoring with strace. It looks like head exits but find continues searching. This was only observable the first run since some caching seems to be done which makes subsequent runs complete too fast to tell, but if I reset the VM I can reproduce.

owner@ubuntu1604-x64-vm:~$ ( trap '' pipe; find / -name initrd* 2>/dev/null | strace -e 'trace=!all' head -n 1)
/initrd.img
+++ exited with 0 +++
(few seconds wait)

Since we only need the first line I can just use find options -print -quit and skip piping to head. But say we needed the first n results, how would I do that with head and get find to terminate rather than continue searching?

find (GNU findutils) 4.7.0-git
head (GNU coreutils) 8.25

Also: I've tried to subscribe to your mailing list but received no acknowledgement. I also tried the password recovery form and received no acknowledgement. Please CC me on any reply. Thanks




reply via email to

[Prev in Thread] Current Thread [Next in Thread]