http://qs321.pair.com?node_id=11117908


in reply to Second background process is pausing the gui

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re: Second background process is pausing the gui

Replies are listed 'Best First'.
Re^2: Second background process is pausing the gui
by bliako (Monsignor) on Jun 11, 2020 at 10:59 UTC

    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

Re^2: Second background process is pausing the gui
by Anonymous Monk on Jun 10, 2020 at 14:08 UTC
    mike, please stop. you don't know what you're talking about.
    A reply falls below the community's threshold of quality. You may see it by logging in.