Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close command used to determine file size #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lucaswerkmeister
Copy link
Contributor

When an AWK program reads from a file or process, AWK keeps the connection to the file or process open until the program explicitly closes it. This is useful in order to read multiple lines from a file, or to keep reading input from a long-running coprocess, but it also means that we must make sure to close any short helper program we launch, otherwise we will leak one file descriptor (the pipe to the child process) per invocation and eventually run out of file descriptors (EMFILE Too many open files). (See also the time() function for an example where we already do this.)

Fixes #9.

When an AWK program reads from a file or process, AWK keeps the
connection to the file or process open until the program explicitly
closes it. This is useful in order to read multiple lines from a file,
or to keep reading input from a long-running coprocess, but it also
means that we must make sure to close any short helper program we
launch, otherwise we will leak one file descriptor (the pipe to the
child process) per invocation and eventually run out of file descriptors
(EMFILE Too many open files). (See also the time() function for an
example where we already do this.)

Fixes dspinellis#9.
@lucaswerkmeister
Copy link
Contributor Author

And about 20 minutes later, I can confirm that this indeed fixes #9 :) I ran both old and new versions of pmonitor against the same cp process, and the unpatched one ran out of file descriptors again while the new one continues running. (Listing the contents of /proc/PID/fd/ also shows that the unpatched version is leaking pipe file descriptors while the other one isn’t.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

“too many open files” error in awk
1 participant