What happens with the completion of a perl script?

This question is specific to perl, in the context that I specifically wonder what happens with file descriptors (both working and not) when, at some point, the script diehas open descriptors.

So, what operations are performed as the execution occurs until the last line of the script? Script level? Perl Level? Shell level (e.g. bash)? System level (for example, suppose a modern * nix such as Ubuntu)?

Here is some information that I have found so far, although there are no direct answers:

Perl Script Shutdown Recommendations

Make sure custom code runs when exiting perl

Why close file descriptors in perl (sys buffers)

Perldoc on dieand exitspeaks mostly about the functions themselves.

+4
source share
2 answers

Perl uses a link counting strategy to collect garbage. When the number of reference variables reaches 0, any applicable method is called DESTROYbefore freeing its memory for the perl memory management system.

As your program completes, the remaining variables will go out of scope and their reference count will decrease. This is the moment when your files will be closed.

perl , , , (, init ) .


: , , , 0, DESTROY, , perl DESTROY / , .

+1

/, / .

perl . interuptors - IO. .

-1

All Articles