Thread fork problem: mal wieder.. (10 answers)
Opened by steinwolf at 2003-11-08 17:52

esskar
 2003-11-08 22:46
#70647 #70647
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    sub pipe_to_fork ($) {
       my $parent = shift;
       pipe(my $child, $parent) or die;
       my $pid = fork();
       die "fork() failed: $!" unless defined $pid;
       if ($pid) {
           close $child;
       }
       else {
           close $parent;
           open(STDIN, "<&=" . fileno($child)) or die;
       }
       $pid;
   }

   if (pipe_to_fork('FOO')) {
       # parent
       print FOO "pipe_to_fork\n";
       close FOO;
   }
   else {
       # child
       while (<STDIN>) { print; }
       close STDIN;
       exit(0);
   }
\n\n

<!--EDIT|esskar|1068423759-->

View full thread fork problem: mal wieder..