Home > Archive > PERL Beginners > June 2005 > sys_wait_h and waitpid
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
sys_wait_h and waitpid
|
|
| Bryan R Harris 2005-06-07, 3:55 am |
|
All,
I've written a simple daemon to launch processes, and I check for the exit
status of those processes. According to "Programming Perl", I need to use
the following:
use POSIX qw(:sys_wait_h);
However on OS X (no jabs or snide remarks, please, today was painful enough!
=), it says:
":sys_wait_h" is not exported by the POSIX module
If I remove it, it runs under OS X, but then under IRIX it takes 8+ seconds
just to do a waitpid call, which is way too long for this application. With
it in there, it runs instantly on IRIX.
Any ideas?
- B
| |
| Chris Devers 2005-06-07, 3:55 am |
| On Mon, 6 Jun 2005, Bryan R Harris wrote:
> Any ideas?
Wrap the use() statement in an if block.
if ( $^O eq 'darwin' ) {
use POSIX;
} else {
use POSIX qw(:sys_wait_h);
}
Will that work?
--
Chris Devers
| |
| Wiggins d'Anconia 2005-06-07, 3:55 am |
| Chris Devers wrote:
> On Mon, 6 Jun 2005, Bryan R Harris wrote:
>
>
>
>
> Wrap the use() statement in an if block.
>
> if ( $^O eq 'darwin' ) {
> use POSIX;
> } else {
> use POSIX qw(:sys_wait_h);
> }
>
> Will that work?
>
>
Only if you wrap that in a BEGIN block. Remember, 'use' happens at
compile not run time.
http://danconia.org
| |
| Bryan R Harris 2005-06-08, 3:57 am |
|
>
> Only if you wrap that in a BEGIN block. Remember, 'use' happens at
> compile not run time.
Here's what I tried:
**************************************
BEGIN {
if ( $^O eq 'darwin' ) { use POSIX; }
else { use POSIX qw(setsid nice :sys_wait_h); } # line 14
}
**************************************
.... but it still errors out:
% sko
":sys_wait_h" is not exported by the POSIX module
Can't continue after import errors at
/System/Library/Perl/5.8.1/darwin-thread-multi-2level/POSIX.pm line 19
BEGIN failed--compilation aborted at /Users/bh/Library/perl/sko line 14.
% perl -e 'print $^O, "\n";'
darwin
Any other ideas?
TIA.
- Bryan
| |
| Paul Johnson 2005-06-08, 3:57 am |
| On Tue, Jun 07, 2005 at 08:23:43AM -0700, Bryan R Harris wrote:
>
No.
[color=darkred]
And not even then.
[color=darkred]
This is true, but BEGIN happens at compile time too so you've not gained
much.
[color=darkred]
> Here's what I tried:
>
> **************************************
> BEGIN {
> if ( $^O eq 'darwin' ) { use POSIX; }
> else { use POSIX qw(setsid nice :sys_wait_h); } # line 14
> }
>
> ... but it still errors out:
> Any other ideas?
"perldoc -f use" reminds us that "use Module LIST" is exactly
equivalent to
BEGIN { require Module; import Module LIST; }
so:
BEGIN
{
require POSIX;
POSIX->import($^O ne "darwin" ? qw(setsid nice :sys_wait_h) : ())
}
--
Paul Johnson - paul@pjcj.net
http://www.pjcj.net
| |
| Bryan R Harris 2005-06-08, 3:57 am |
|
>
> No.
>
>
> And not even then.
>
>
> This is true, but BEGIN happens at compile time too so you've not gained
> much.
>
>
>
> "perldoc -f use" reminds us that "use Module LIST" is exactly
> equivalent to
>
> BEGIN { require Module; import Module LIST; }
>
> so:
>
> BEGIN
> {
> require POSIX;
> POSIX->import($^O ne "darwin" ? qw(setsid nice :sys_wait_h) : ())
> }
That seems to work, and there's *no way* I'd have ever figured that out on
my own.
Thanks Paul!
- Bryan
|
|
|
|
|