in reply to interrupt buffered output
This will attempt to close (and therefore flush) all open files (with filenos 0 .. 255) when ^C is received:
require POSIX; $SIG{INT} = sub{ warn 'Interupted'; POSIX::close( $_ ) for 0 .. 255; exit; };
You might also want to install the same signal handler for ^Break also:
require POSIX; $SIG{BREAK} = $SIG{INT} = sub{ warn 'Interrupted'; POSIX::close( $_ ) for 0 .. 255; exit; };
If you are opening and closing many files then you might need to increase the range. The limit will depend upon who/how your copy of perl was built. With the version of AS perl on my system the limit appears to be 2047 concurrent handles. I'm not sure if that information is available via Config somewhere?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: interrupt buffered output
by derby (Abbot) on Jan 19, 2007 at 20:45 UTC |