![]() |
1 Attachment(s)
[QUOTE=chalsall;308266]
I'm particularly interested in those who run ActiveState's Perl, and/or cygwin's. [/QUOTE] Me ActiveState. [CODE] This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x64-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2011, Larry Wall Binary build 1402 [295342] provided by ActiveState http://www.ActiveState.com Built Oct 7 2011 15:19:36 [/CODE][CODE] C:\Computing>perl -w fork.pl Entering TestFork... Entering pipe_from_fork...[/CODE]No output at all in your version. I added some prints, find attached. |
[QUOTE=Brain;308275]Me ActiveState.
[CODE] C:\Computing>perl -w fork.pl Entering TestFork... Entering pipe_from_fork...[/CODE]No output at all in your version. I added some prints, find attached.[/QUOTE] Thank you very much Brain. Important data. So it is dying (or freezing) in pipe_from_fork. Could I ask you to change the pipe_from_fork subroutine to this, and then run again? [CODE]sub pipe_from_fork ($) { my $parent = shift; print "pipe_from_fork - 1 -- $$\n"; pipe $parent, my $child or die; print "pipe_from_fork - 2 -- $$\n"; my $pid = fork(); print "pipe_from_fork - 3 -- $$\n"; die "fork() failed: $!" unless defined $pid; print "pipe_from_fork - 4 -- $$ -- PID: $pid\n"; if ($pid) { print "pipe_from_fork - 5 -- $$ -- PID: $pid\n"; close $child; print "pipe_from_fork - 5.1 -- $$ -- PID: $pid\n"; } else { print "pipe_from_fork - 6 -- $$\n"; close $parent; print "pipe_from_fork - 6.1 -- $$\n"; open(STDOUT, ">&=" . fileno($child)) or die; print "pipe_from_fork - 6.2 -- $$\n"; } print "pipe_from_fork - 7 -- $$\n"; $pid; } [/CODE] |
1 Attachment(s)
Ready.
[CODE]Entering TestFork... Entering pipe_from_fork... pipe_from_fork - 1 -- 3440 pipe_from_fork - 2 -- 3440 pipe_from_fork - 3 -- 3440 pipe_from_fork - 4 -- 3440 pipe_from_fork - 5 -- 3440 pipe_from_fork - 7 -- 3440 pipe_from_fork - 3 -- -5324 pipe_from_fork - 4 -- -5324 pipe_from_fork - 6 -- -5324[/CODE]Not terminating on its own. |
[QUOTE=Brain;308277]Ready.
[CODE]Entering TestFork... Entering pipe_from_fork... pipe_from_fork - 1 -- 3440 pipe_from_fork - 2 -- 3440 pipe_from_fork - 3 -- 3440 pipe_from_fork - 4 -- 3440 pipe_from_fork - 5 -- 3440 pipe_from_fork - 7 -- 3440 pipe_from_fork - 3 -- -5324 pipe_from_fork - 4 -- -5324 pipe_from_fork - 6 -- -5324[/CODE]Not terminating on its own.[/QUOTE] OK. Thanks. One last code change (above) which I'd love if you could run. I suspect that 6 will return, but 6.1 might not, and 6.2 won't. I don't understand why yet. Thanks for your help with this. |
Nice experiment here. Strawberry, 5.16, 64 bits.
I added few prints into it: [CODE] #!/usr/bin/perl -w TestFork(1); TestFork(2); exit; sub TestFork { ($Test) = @_; print "one ${Test}\n"; if (pipe_from_fork('BAR')) { # parent print "two ${Test}\n"; while (<BAR>) { print; } print "three ${Test}\n"; close BAR; print "\n\nTest completed. Was output seen from the child?\n\n\n"; } else { # child print "four ${Test}\n"; if ($Test == 1) { print "five ${Test}\n"; for ($Cnt = 0; $Cnt<5; $Cnt++) { print "We're here! Cnt: ${Cnt}\n"; sleep(1); } print "six ${Test}\n"; exit(0); } else { print "seven ${Test}\n"; exec("dir"); print "eight ${Test}\n"; } } } sub pipe_from_fork ($) { print "inside 1\n"; my $parent = shift; pipe $parent, my $child or die; print "inside 2\n"; my $pid = fork(); die "fork() failed: $!" unless defined $pid; print "inside 3\n"; if ($pid) { close $child; print "inside 4\n"; } else { close $parent; open(STDOUT, ">&=" . fileno($child)) or die; print "inside 5\n"; } print "outside\n"; $pid; } [/CODE] The output: [CODE] >perl chalsall.pl Statement unlikely to be reached at chalsall.pl line 33. (Maybe you meant system() when you said exec()?) one 1 inside 1 inside 2 inside 3 inside 4 [COLOR=RoyalBlue]outside inside 3[/COLOR] two 1 Terminating on signal SIGINT(2) [/CODE] (it does not terminate by itself, need ctrl+c). The blue lines, "outside" and the second "inside 3" lines, are sometime exchanged, if i run it many times, this means he is really multitasking there, the blue "inside 3" is print by the forked process which is faster sometimes. What else is doing, no idea... |
1 Attachment(s)
[QUOTE=chalsall;308278]OK. Thanks.
One last code change (above) which I'd love if you could run. I suspect that 6 will return, but 6.1 might not, and 6.2 won't. I don't understand why yet. Thanks for your help with this.[/QUOTE] Not terminating...[CODE] Entering TestFork... Entering pipe_from_fork... pipe_from_fork - 1 -- 2344 pipe_from_fork - 2 -- 2344 pipe_from_fork - 3 -- 2344 pipe_from_fork - 4 -- 2344 -- PID: -6040 pipe_from_fork - 5 -- 2344 -- PID: -6040 pipe_from_fork - 3 -- -6040 pipe_from_fork - 4 -- -6040 -- PID: 0 pipe_from_fork - 5.1 -- 2344 -- PID: -6040 pipe_from_fork - 7 -- 2344 pipe_from_fork - 6 -- -6040 pipe_from_fork - 6.1 -- -6040[/CODE] |
with my main and your function:
[CODE]one 1 pipe_from_fork - 1 -- 2652 pipe_from_fork - 2 -- 2652 pipe_from_fork - 3 -- 2652 pipe_from_fork - 4 -- 2652 -- PID: -4404 pipe_from_fork - 5 -- 2652 -- PID: -4404 pipe_from_fork - 3 -- -4404 pipe_from_fork - 5.1 -- 2652 -- PID: -4404 pipe_from_fork - 4 -- -4404 -- PID: 0 pipe_from_fork - 7 -- 2652 pipe_from_fork - 6 -- -4404 two 1 pipe_from_fork - 6.1 -- -4404 Terminating on signal SIGINT(2)[/CODE] |
I'm running ActivePerl 5.10.1 Build 1006 and get the same result as Brain:[code]C:\Aliquot\Data>perl fork.pl
Entering TestFork... Entering pipe_from_fork... pipe_from_fork - 1 -- 5272 pipe_from_fork - 2 -- 5272 pipe_from_fork - 3 -- 5272 pipe_from_fork - 4 -- 5272 -- PID: -4680 pipe_from_fork - 5 -- 5272 -- PID: -4680 pipe_from_fork - 5.1 -- 5272 -- PID: -4680 pipe_from_fork - 7 -- 5272 pipe_from_fork - 3 -- -4680 pipe_from_fork - 4 -- -4680 -- PID: 0 pipe_from_fork - 6 -- -4680 pipe_from_fork - 6.1 -- -4680[/code]Also with no termination.... |
[QUOTE=Brain;308280]Not terminating...[/QUOTE]
OK. Thanks Brain and LaurV and schickel. So the Perl statement "open(STDOUT, ">&=" . fileno($child)) or die;" doesn't work under Windows. Even though it is supposed to. Hmmmm.... |
How about using the piped version of open? Here's something I whipped up a while back to run mfaktc from Perl. Works on activestate and cygwin.
[code] open (MFAKTC, "$mfaktc_bin -tf $this_exp $this_depth $this_depth_end |"); my $factor_found = 0; my $ok_end = 0; while ($line = <MFAKTC>) { print LOG $line; if ($line =~ /found \d+ factor\(s\) for M/) { $factor_found = 1; } elsif ($line =~ /cleared assignment/) { $ok_end = 1; } } close MFAKTC; [/code] Might make it more difficult to run multiple copies of mfaktc, though |
[QUOTE=kjaget;308289]How about using the piped version of open? Here's something I whipped up a while back to run mfaktc from Perl. Works on activestate and cygwin.[/QUOTE]
According to the documentation, that's not supposed to work. But clearly the documentation is wrong. I'll drill down on your example shortly. Thanks Kevin. :smile: |
| All times are UTC. The time now is 13:38. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.