APM: system call hangs
Bakken, Tom - Temple, TX
tom.bakken at tx.usda.gov
Thu Jul 22 13:02:29 CDT 2004
perl -v = This is perl, version 5.005_03 built for MSWin32-x86-object
Surprise?!!???!! Bill, you hit the nail on the head. I've got a newer
version on another machine I should be able to use instead.
Thanks for all your help.
Tom Bakken
-----Original Message-----
From: Bill Raty [mailto:bill.raty at gmail.com]
Sent: Thursday, July 22, 2004 11:33 AM
To: Bakken, Tom - Temple, TX
Subject: Re: APM: system call hangs
What version of perl? Activestate perl has support 'fork' since
5.6.mumble . Please post results of perl -v
Regards,
-Bill
On Thu, 22 Jul 2004 07:45:41 -0600, Bakken, Tom - Temple, TX
<tom.bakken at tx.usda.gov> wrote:
> 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/ccacbb0b/Tom.Bakkentx.usda.gov.vcf
More information about the Austin
mailing list