APM: system call hangs

Bakken, Tom - Temple, TX tom.bakken at tx.usda.gov
Thu Jul 22 08:45:41 CDT 2004


The system I'm running this on (Windows 2000 Server) doesn't seem to
support fork.  I'm digging through the ActivePerl documentation and
there seems to be some support for emulating UNIX.  I tried:

use POSIX qw(setsid);
use POSIX qw(:errno_h :fcntl_h);

But that didn't help.  Is there another module that would work?

I appreciate your help.

-----Original Message-----
From: Bill Raty [mailto:bill.raty at gmail.com] 
Sent: Wednesday, July 21, 2004 10:50 AM
To: Bakken, Tom - Temple, TX
Subject: Re: APM: (no subject)


Tom,

"System" is itself a form of IPC that has been neatly bundled to cover
the majority case usage (running a well behaved short-lived
subprocess).  However you're needing behavior that isn't exactly
covered by "system".

Take a look at the 2nd edition of the Perl Cookbook, especially the
piped open commands.  You'll probably also need to fork off a process
to do the reading so that your parent process can control how long it
is willing to wait.

You may also be able to tap directly into the Windows API via the COM
module that are supplied with ActiveState perl interpreter, rather

-- BEGIN SHAMELESS PLUG --
I'll be presenting some syntactic sugar to sweeten the experience of
controling child processes at Perl monger's tonight.
-- END SHAMELESS PLUG --


Here is example code that I'll be covering tonight which spawns off a
child process and terminates it after five seconds.  First the
syntactic sugar subroutine:

  sub spawn (&) {
    my ($coderef) =  @_;
    my $pid;
    unless ($pid = fork) {
      # start the child process.  make sure we exit too!
      $coderef->();
      exit;
    }
    # make sure we don't have ghost processes.  Have perl do the waitpid
    $SIG{CHLD} = "IGNORE";  
    # return the process id of the child process.
    return $pid;
  }

#############################
# Now the using code
#############################
# start a process to count from 1 to 100 in 1 second intervals.
Interrupt it
# after 5 seconds
my $kidpid = spawn {
  # this is running in a different process
  foreach (1 .. 100) {
    print "$_\n";
    sleep 1;
  }
};  # <--- REMEMBER THE SEMICOLON HERE!!!

# let child run for 5 seconds, then stop it.
sleep 5;
kill TERM => $kidpid;

__END__

In your case you'd probably put the system call inside the curly
braces after the 'spawn' invocation.  You'll probably need to include
the code that acts upon  the status code from the 'system' command
into the curly as well, since that is running in a separate perl
process.

On Wed, 21 Jul 2004 08:12:46 -0600, Bakken, Tom - Temple, TX
<tom.bakken at tx.usda.gov> wrote:
> I'm having trouble with the perl "system" function.  Actually system
> works fine.  It's the windows 2000 server programs it runs that are
> giving me fits.  When I do this:
> 
> $Status = system("uptime \\\\$MachineName > /nul");
> Or
> $Status = system("if exist p:\nul net use p: /d");
> 
> For example, the uptime or net use will sometimes hang or stall.  How
> can I kill these and continue without aborting the entire program?
> 
> I've looked through some of the texts regarding interprocess
> communications but I'm not sure that's the way I should go.
> 
> Tom Bakken
> 
> 
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Tom.Bakken at tx.usda.gov.vcf
Type: text/x-vcard
Size: 460 bytes
Desc: Tom.Bakken at tx.usda.gov.vcf
Url : http://mail.pm.org/pipermail/austin/attachments/20040722/21de2770/Tom.Bakkentx.usda.gov.vcf


More information about the Austin mailing list