Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Second background process is pausing the gui

by Anonymous Monk
on Jun 10, 2020 at 14:02 UTC ( #11117908=note: print w/replies, xml ) Need Help??


in reply to Second background process is pausing the gui

That open() call is inherently synchronous: it will execute the command, wait for it to finish, and return the output to you as $status.
  • 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 (Prior) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11117908]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2020-09-29 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (146 votes). Check out past polls.

    Notices?