It will be asynchronous in the sense that the command output can be read while it is being executed (as a child process). Otherwise it is synchronous in the sense that you can't move outside the scope of the filehandle $xx without explicitly killing the child.

This is the normal usage based on "Perl Cookbook"'s "16.4. Reading or Writing to Another Program" (edit: sorry for pirated link! I did not know, thanks Fletch)

my $pid = open(my $xx, "od -w1 -v -An -N5 -td1 < /dev/random 2>&1|") or die "fork: $!"; if( $pid ){ while(<$xx>){ print "read: $_"; } } close($xx) or die "command failed with ".($?>>8);

The following code demonstrates what I mean by "outside the scope of the filehandle". At the goto it waits for the spawned command to be finished:

{ my $pid = open(my $xx, "sleep 10|") or die "fork: $!"; if( $pid ){ goto XX; while(<$xx>){ print "read: $_"; } } close($xx) or die "command failed with ".($?>>8); } XX: print "here\n";

You will notice that "here" is printed only upon script exit. Whereas, the following executes the goto because it is within scope but script does not exit until sleep exits. Perhaps half-asynchronously would be a better term ;)

my $pid = open(my $xx, "sleep 10|") or die "fork: $!"; if( $pid ){ goto XX; while(<$xx>){ print "read: $_"; } } close($xx) or die "command failed with ".($?>>8); XX: print "here\n";

"here" is printed at the goto, then there is implicit waiting for sleep to end.

bw, bliako


In reply to Re^2: Second background process is pausing the gui by bliako
in thread Second background process is pausing the gui by Ohad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.