Re: BEGIN, INIT etc...

Re: BEGIN, INIT etc...

am 29.03.2008 14:23:02 von Bart Lateur

Joost Diepenmaat wrote:

>END blocks are useful to "guarantee" that code gets run when the program
>ends, even if for example an exception is thrown. Useful for system
>resources that may not get freed properly otherwise.

Unfortunately they're still not called on exit and on exec.

--
Bart.

Re: BEGIN, INIT etc...

am 29.03.2008 21:49:31 von Ilya Zakharevich

[A complimentary Cc of this posting was sent to
Bart Lateur
], who wrote in article :
> Joost Diepenmaat wrote:
>
> >END blocks are useful to "guarantee" that code gets run when the program
> >ends, even if for example an exception is thrown. Useful for system
> >resources that may not get freed properly otherwise.
>
> Unfortunately they're still not called on exit and on exec.

You mean "Fortunately they are not called on _exit(); do not forget to
never use exec()"?

[END() IS called on exit(). Signal handlers can be installed to die()
on signal, so END() is called on signals.]

Hope this helps,
Ilya

Re: BEGIN, INIT etc...

am 29.03.2008 23:30:37 von Ben Morrow

Quoth Ilya Zakharevich :
> [A complimentary Cc of this posting was sent to
> Bart Lateur
> ], who wrote in article
> :
> > Joost Diepenmaat wrote:
> >
> > >END blocks are useful to "guarantee" that code gets run when the program
> > >ends, even if for example an exception is thrown. Useful for system
> > >resources that may not get freed properly otherwise.
> >
> > Unfortunately they're still not called on exit and on exec.
>
> You mean "Fortunately they are not called on _exit();

Well, no, that's kind-of the point...

> do not forget to never use exec()"?

I am confused. How is one (on a fork/exec-based system, or perl's
emulation of such under Win32) supposed to avoid calling exec when
necessary?

> [END() IS called on exit(). Signal handlers can be installed to die()
> on signal, so END() is called on signals.]

END blocks are not called when a process exits because of the DEFAULT
action of a signal. It is of course possible to fix this by installing
an appropriate signal handler.

Ben

Re: BEGIN, INIT etc...

am 30.03.2008 09:43:40 von Ilya Zakharevich

[A complimentary Cc of this posting was sent to
Ben Morrow
], who wrote in article :
> > do not forget to never use exec()"?
>
> I am confused. How is one (on a fork/exec-based system, or perl's
> emulation of such under Win32) supposed to avoid calling exec when
> necessary?

The situations when it is *necessary* to call exec() do exist. But
they are extremely rare. fork() is useful slightly more often; but
again, these situations are in no way frequent.

[The introduction of fork()/exec() mess is one of the major weaknesses
of *nix. Fortunately, Perl API makes it practically never needed.]

Yours,
Ilya