LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-20-2011, 02:11 AM   #1
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Rep: Reputation: 36
perl - reading from a pipe


Hi Folks, I seem to be having a problem doing a simple IPC between a child and a parent process. The child process runs a command and writes the output into a pipe which the parent reads. My program seems to be getting into some sort of a blocking state when i do
Code:
@from_pipe = <READX>
,but works for
Code:
$from_pipe = <READX>
. I have this code as an example.Is my program suffering from buffering ?? Thanks !!
Code:
#!/usr/bin/perl
use strict;
use warnings;
use POSIX;
use IO::Handle;

#
pipe (READ,WRITE);
#
sub _Forked {
    my $ip = shift;
    die "Couldn't fork" unless defined (my $pid = fork());
    if ($pid == 0) {
        # CHILD
        my @ping = `ping $ip -w 2 -q | sed -n '\$p'`;
        close (READ);
        select WRITE;
        print "@ping\n";
        close (WRITE);
        #
        exit (0);
    }
    #
    return ($pid);
}
#
sub main {
    my $cpid = _Forked('4.2.2.2');

    my $dpid;
    do {
        $dpid   = POSIX::waitpid(-1,WUNTRACED); 
        my @val = <READ>;
        print "@val\n";
        #
        my $cpid = _Forked('4.2.2.2');
    
    } until ($dpid < 0)
}
main();
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] perl fork & pipe help kdelover Programming 5 04-09-2011 08:42 AM
Perl experts: I need to run shell command from perl using pipe idreesedu Programming 14 01-11-2011 04:52 PM
Perl alarm not working when reading for a socket , perl seems to be buggy alix123 Programming 1 10-05-2008 07:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration