in reply to eof() blocking
From perldoc -f eof
Note that this function actually reads a character and then "ungetc"s it, so isn't useful in an interactive context.What I would do instead:
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11123397 use warnings; use Socket; my $child; #filehandle to child process my $parent; #filehandle to parent process my $pid; #Process ID of child process socketpair($child, $parent, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $! +"; $child->autoflush(1); $parent->autoflush(1); if ($pid = fork()) { close $parent or die "close: $!\n"; sleep 1; print STDOUT time%1000, ": polling child\n"; my $buf = ''; while( sysread $child, $buf, 4096, length $buf ) { while( $buf =~ s/(.*)\n// ) { print STDOUT time%1000, ": received <$1>\n"; } } print STDOUT time%1000, ": end of input from child\n"; wait; } elsif( defined $pid ) { close $child or die "close: $!\n"; print STDOUT time%1000, ": child started\n"; sleep 5; print $parent time%1000, ": child printed\n"; close $parent or die "close: $!\n"; exit; } else { die "cannot fork: $!"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: eof() blocking
by azadian (Sexton) on Nov 05, 2020 at 10:07 UTC | |
by tybalt89 (Monsignor) on Nov 05, 2020 at 15:15 UTC | |
by tybalt89 (Monsignor) on Nov 05, 2020 at 15:51 UTC |
In Section
Seekers of Perl Wisdom