![]() |
|
|
#12 | |
|
Dec 2009
Peine, Germany
5138 Posts |
Quote:
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:
C:\Computing>perl -w fork.pl Entering TestFork... Entering pipe_from_fork... Last fiddled with by Brain on 2012-08-17 at 16:47 Reason: added Perl version info |
|
|
|
|
|
|
#13 | |
|
If I May
"Chris Halsall"
Sep 2002
Barbados
260216 Posts |
Quote:
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;
}
Last fiddled with by chalsall on 2012-08-17 at 17:11 |
|
|
|
|
|
|
#14 |
|
Dec 2009
Peine, Germany
5138 Posts |
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 Last fiddled with by Brain on 2012-08-17 at 17:09 Reason: attachment fixed |
|
|
|
|
|
#15 | |
|
If I May
"Chris Halsall"
Sep 2002
Barbados
260216 Posts |
Quote:
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. |
|
|
|
|
|
|
#16 |
|
Romulan Interpreter
Jun 2011
Thailand
2·5·312 Posts |
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:
>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
outside
inside 3
two 1
Terminating on signal SIGINT(2)
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... |
|
|
|
|
|
#17 | |
|
Dec 2009
Peine, Germany
331 Posts |
Quote:
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 |
|
|
|
|
|
|
#18 |
|
Romulan Interpreter
Jun 2011
Thailand
2·5·312 Posts |
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) |
|
|
|
|
|
#19 |
|
"Frank <^>"
Dec 2004
CDP Janesville
2×1,061 Posts |
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 |
|
|
|
|
|
#20 |
|
If I May
"Chris Halsall"
Sep 2002
Barbados
2×5×7×139 Posts |
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.... Last fiddled with by chalsall on 2012-08-17 at 17:38 Reason: s/Thanks Brain and LuarV/Thanks Brain and LaurV and schickel/ |
|
|
|
|
|
#21 |
|
Jun 2005
3×43 Posts |
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;
|
|
|
|
|
|
#22 | |
|
If I May
"Chris Halsall"
Sep 2002
Barbados
100110000000102 Posts |
Quote:
But clearly the documentation is wrong. I'll drill down on your example shortly. Thanks Kevin.
|
|
|
|
|
![]() |
| Thread Tools | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Automatic submit results + fetch assignments for mfaktc? | DuskFalls | GPU Computing | 5 | 2017-12-02 00:34 |
| Simple Script to get Trial Factoring Work | jfamestad | PrimeNet | 3 | 2016-11-06 20:32 |
| Why trial factoring work chopped into chunks? | lidocorc | PrimeNet | 4 | 2008-11-06 18:48 |
| How does the trial factoring work with 15K*2^n-1 | jocelynl | 15k Search | 0 | 2003-07-11 14:23 |
| How does trial-factoring work? | ThomRuley | Software | 5 | 2003-05-30 20:34 |