If I am writing a Perl script that overwrites STDERR with a duplicate of STDOUT but I never restore the filehandle, what happens at the end of script execution? I can't find anything that warns against what actually occurs or doesn't occur.

I'm probably misinformed but thanks for your patience.

有帮助吗?

解决方案

When a process exits, the kernel recovers all used resources. This includes all the file descriptors, which are simply closed. If there is an application-level buffer, data in that buffer may not have been written to the kernel, but otherwise there is no risk in keeping file descriptors open before exiting.

If your Perl script ends by using exec to launch another process, that process will inherit all the file descriptors (except those marked as close on exec).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top