On Wed, Jul 25, 2001 at 03:15:11PM -0400, mp kapa wrote:
> Iam working on Interprocess communication using pipes in Windows platform. 
> Iam trying to establish communication between two childs of the same parent 
> process. I have written the program like this.

While this may be what you want, it's not what you're getting.


 
> #!/usr/bin/perl -W

You should probably use -w, not -W.  -W forces warnings even on code that
tries to turn specific warnings off.

You should also add 'use strict'.


[snip]
> $pid = fork();
> $pid1 = fork();

This double fork causes three processes to be created, for a total of four.
>From your description, I take it you only wanted to create two processes,
both children of the initial process.

Consider this neat little diagram I thought up to try to illustrate the
problem (fixed width font required to view it correctly):

    |       - your initial process
    |
    |
   / \      - $pid = fork();
  /   \
 /\   /\    - $pid1 = fork();
/  \ /  \

The problem is your second fork isn't conditional on whether or not the
current process is the parent process.  It gets executed in both processes.

This is probably more like what you were intending (with checks of the fork
added, you should almost always check system calls):

    my $pid = fork();
    die("fork failed: \l$!.\n") unless defined($pid);

    my $pid1;
    if ($pid) {
        $pid1 = fork();
        die("fork failed: \l$!.\n") unless defined($pid1);
    }
[snip]


> The above program is running perfectly on Linux, but when I tried to run 
> this program in Windows(perl version 5.6.0) still it is running but the 
> program is not terminating. Can anyone help me in this matter.

This may have to do with the forking problem I described above.  Let us know
if you're still having problems.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to