Large file problem with either grep and head

Solution Verified - Updated -

Issue

  • SIGPIPE is blocked and grep doesn't handle EPIPE so it prints error after error. In this case grep is ignoring SIGPIPE, grep doesn't exit, it keeps trying to write and keeps getting EPIPE and keeps printing an error, that is the unwanted behavior.

  • When SIGPIPE is not ignored, the default behavior is to terminate the process. So in the normal case, grep exits when getting SIGPIPE (because it isn't ignored) and never sees EPIPE so the question is why not handle EPIPE, maybe print one error, then exit with non-zero exit code in the case where SIGPIPE is blocked by the silly shell.

Environment

  • Red Hat Enterprise Linux 6

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.