Jeff Horwitz on 7 Jan 2004 20:56:43 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: process in the background


actually, it looks like perlipc tells you to use "system" to run processes
in the background.  the behavior is quite different.  for example:

[jeff@groovy jeff]$ perl -e 'system("(sleep 2;echo shell)&");print "script\n";'
script
[jeff@groovy jeff]$ shell

the (almost) same thing run with backticks blocks waiting for the children:

[jeff@groovy jeff]$ perl -e 'print `(sleep 2;echo "shell")&`;print "script\n";'
shell
script

-jeff

On Wed, 7 Jan 2004, Jeff Abrahamson wrote:

> According to perlipc, this should work:
>
>     perl -e '$x=`(sleep 2;hostname)&`;print $x;'
>
> That is, it should print nothing and terminate.
>
> In fact, it takes two seconds before perl prints my hostname and
> terminates.
>
> Maybe perl is waiting on its children before terminating or cares that
> I am looking at the command's stdout.  But I don't think so:
>
>     perl -e '`(sleep 2;hostname) &`;print "0\n";sleep 1;print "1\n";sleep 1;print "2\n";'
>
> waits two seconds before it prints 0, 1, 2 separated by a second each.
>
>
> Any ideas what's going on here?
>
> Of course, I can use fork directly...
>
> --
>  Jeff
>
>  Jeff Abrahamson  <http://www.purple.com/jeff/>
>  GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B
> -
> **Majordomo list services provided by PANIX <URL:http://www.panix.com>**
> **To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
>

-
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**