Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env perl
- # http://stackoverflow.com/q/12640993/132382
- #
- # XXX - !!Error checking removed!!
- #
- # This produces:
- # -- SIGIO --
- # -- SIGIO --
- # -- SIGIO --
- # done
- use strict; use warnings;
- use Fcntl;
- use v5.16;
- $SIG{IO}= sub { say "-- SIGIO --" };
- my ($fh);
- if (! open($fh, '-|')) { # XXX Error checking
- # Child
- for ('one', 'two') {
- sleep 2;
- say;
- }
- exit;
- }
- # Parent
- fcntl($fh, F_SETFL, fcntl($fh, F_GETFL, 0) | O_ASYNC); # XXX Error checking
- fcntl($fh, F_SETOWN, 0 + $$);
- # Wait a bit
- while (time < ($^T + 10)) {
- sleep 1;
- }
- say "done";
Advertisement
Add Comment
Please, Sign In to add comment