Closed p5pRT closed 21 years ago
op/fork..............PROG: if ($pid = fork()) { print "forked first kid\n"; print "waitpid() returned ok\n" if waitpid($pid\,0) == $pid; } else { print "first child\n"; exit(0); } if ($pid = fork()) { print "forked second kid\n"; print "wait() returned ok\n" if wait() == $pid; } else { print "second child\n"; exit(0); } EXPECTED: forked first kid first child waitpid() returned ok forked second kid second child wait() returned ok GOT: first child forked first kid waitpid() returned ok second child forked first kid waitpid() returned ok forked second kid wait() returned ok FAILED at test 17
In article \200008180053\.e7I0r5h29919@​garcia\.efn\.org\, I wrote:
op/fork..............PROG: if ($pid = fork()) { print "forked first kid\n"; print "waitpid() returned ok\n" if waitpid($pid\,0) == $pid; } else { print "first child\n"; exit(0); } if ($pid = fork()) { print "forked second kid\n"; print "wait() returned ok\n" if wait() == $pid; } else { print "second child\n"; exit(0); } EXPECTED: forked first kid first child waitpid() returned ok forked second kid second child wait() returned ok GOT: first child forked first kid waitpid() returned ok second child forked first kid waitpid() returned ok forked second kid wait() returned ok FAILED at test 17
Here's a patch:
On Thu\, 17 Aug 2000 17:53:05 PDT\, sthoenna@efn.org wrote:
op/fork..............PROG: if ($pid = fork()) { print "forked first kid\n"; print "waitpid() returned ok\n" if waitpid($pid\,0) == $pid; } else { print "first child\n"; exit(0); } if ($pid = fork()) { print "forked second kid\n"; print "wait() returned ok\n" if wait() == $pid; } else { print "second child\n"; exit(0); } EXPECTED: forked first kid first child waitpid() returned ok forked second kid second child wait() returned ok GOT: first child forked first kid waitpid() returned ok second child forked first kid waitpid() returned ok forked second kid wait() returned ok FAILED at test 17
Looks like you've got the fork() buffering problem that afflicts people without a working fflush(NULL). Try adding $|=1 at the top of that test and see what happens.
Sarathy gsar@ActiveState.com
On Thu\, Aug 17\, 2000 at 06:49:24PM -0700\, Gurusamy Sarathy wrote:
On Thu\, 17 Aug 2000 17:53:05 PDT\, sthoenna@efn.org wrote:
op/fork..............PROG: if ($pid = fork()) { print "forked first kid\n"; print "waitpid() returned ok\n" if waitpid($pid\,0) == $pid; } else { print "first child\n"; exit(0); } if ($pid = fork()) { print "forked second kid\n"; print "wait() returned ok\n" if wait() == $pid; } else { print "second child\n"; exit(0); } EXPECTED: forked first kid first child waitpid() returned ok forked second kid second child wait() returned ok GOT: first child forked first kid waitpid() returned ok second child forked first kid waitpid() returned ok forked second kid wait() returned ok FAILED at test 17
Looks like you've got the fork() buffering problem that afflicts people without a working fflush(NULL). Try adding $|=1 at the top of that test and see what happens.
Ummm\, but does that guarantee much anything about in which order the parent and the kid print their stuff?
Jarkko Hietaniemi \jhi@​iki\.fi wrote
Ummm\, but does that guarantee much anything about in which order the parent and the kid print their stuff?
That was my reaction too when I looked at the test. But the test is sneakier than that - it sorts it's output before checking it.
Mike Guy
On Fri\, Aug 18\, 2000 at 01:32:00PM +0100\, Mike Guy wrote:
Jarkko Hietaniemi \jhi@​iki\.fi wrote
Ummm\, but does that guarantee much anything about in which order the parent and the kid print their stuff?
That was my reaction too when I looked at the test. But the test is sneakier than that - it sorts it's output before checking it.
use D'oh;
Migrated from rt.perl.org#3739 (status was 'resolved')
Searchable as RT3739$