----- Original Message -----
From: "rAuL" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 01, 2002 11:42 AM
Subject: NT Services and Spawning DOS Commands


>
>
> I want to create an application that watches over a specific
directory. When a file is deposited in this directory, the
application beings a very lengthy processing of this file.  When
completed, this input file is moved to another directory called
Done to signal succesful completion.
>
> Since the processing of this input file is quite lengthy,
implementing a multi-threading solution would be ideal but as
you all know, it is not yet implemented with Perl.  The
applicaiton is an NT Service and the processing logic was made
into a another Perl script.  What I did was within my NT
Service, I use the System function to kick off a DOS START
command to start this process.
>
> I think this is ugly but I wanted to know if anyone had any
better suggestions.
> Certainly I would like to keep track of my process via some
kind of PID.
Multi-threading does work in ActivePerl built on Perl 5.6. I am
using build 628 and it seems to work just fine with the fork()
command. Here's a small sample:
#!/usr/bin/perl -w

use strict;

use FileHandle;
use POSIX ":sys_wait_h";

my $kids = 0;
my %children;

while ($kids++ < 5) {
 my $child = fork();

 STDOUT->FileHandle::autoflush(1);
 STDERR->FileHandle::autoflush(1);

 if ($child == 0) {
  print "I am child $kids and my process id is $$\nChild
Sleeping\n";
  sleep(10 + $kids);
  print "I am child $kids and I'm done!\n";
  exit(0);
 } else {
  $children{$child} = 1;
 }
}

my $count = 0;
do {
 print "\nParent: pid $$ sleeping\n";
 sleep(1);
 foreach my $child (keys %children) {
  print "Checking on child: pid $child.\n";
  my $kid = waitpid($child, &WNOHANG);
  $children{$child} = $?;
  print "child pid: $child status: $children{$child} is ";
  if ($kid == $child) {
   print "dead\n";
   delete($children{$child});
  } else {
   print "active\n";
  }
 }
} while (scalar(keys %children));

What version of Perl are you using on what version of Windows
NT?

ego
Edward G. Orton, GWN Consultants Inc.
Phone: 613-764-3186, Fax: 613-764-1721
email: [EMAIL PROTECTED]

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to