Hi,
Suppose if the program runprog.pl takes few hours to
process. the server should be able to process other
clients.........
--- "Swartwood, Larry H" <[EMAIL PROTECTED]>
wrote:
> >if i type "Run" in the client........i want the
> server
> >to execute a program "run.pl" in the background...
> >(that is the server should not wait for the
> completion
> >of the program)
>
> Here's how I do it:
>
> use Win32;
>
> # Create the progress indicator process object.
> my $pid = Win32::Process::Create(
> $new_proc,
> "$perl_path/perl.exe", #
> Whereabouts of Perl
> "perl -X -I $release_path
> $release_path/run.pl", #
> 0, #
> Don't inherit.
> NORMAL_PRIORITY_CLASS |
> CREATE_NO_WINDOW,
> "$release_path")
> or return( &print_error("Error Launching
> prog.pl"));
>
> This creates run.pl as a separate process with no
> affiliation to the server
> program.
>
> >if i type "RunProg" in the client........i want the
> >server to execute a program "runprog.pl"
> >(in this case it needs to wait untill the prog
> >completes).
>
> This one is a little more difficult. Normally (under
> Unix) I would use
> fork(), but I can't get fork() to work under Win2k.
> Here's an alternative:
> runprog.pl could create a semaphore in the form of a
> file on disk and lock
> it with flock. E.g.:
>
> use Fcntl;
>
> sysopen( LOCK_FILE, 'c:/lock', O_CREAT) or die;
> flock( LOCK_FILE, LOCK_EX | LOCK_NB ) or die;
>
> The server program can then check the semaphore and
> if it's still locked
> assume that runprog.pl is running. The way I would
> do this is to try to
> unlock the semaphore in the server program; unlock
> will fail while prog.pl
> has the file locked. E.g.:
>
> # Check the semaphore
> if( flock( LOCK_FILE, LOCK_UN))
> {
> # runprog.pl is finished
> } else {
> # runprog.pl still has the lock
> }
>
> Once runprog.pl stops running, it unlocks the
> semaphore which is then
> detected by the server. E.g.:
>
> # Free the semaphore
> flock( LOCK_FILE, LOCK_UN) or die;
>
> Larry S.
>
>
>
> CODE :-
> -----------
> use IO::Select;
> use IO::Socket;
>
>
> $lsn = new IO::Socket::INET(Listen => 1,
> LocalPort
> => 8080);
> $sel = new IO::Select( $lsn );
>
> while(@ready = $sel->can_read) {
> foreach $fh (@ready) {
> if($fh == $lsn) {
> # Create a new socket
> $new = $lsn->accept;
> $sel->add($new);
> $message = "Request User... $new \n";
> print $message."\n";
> sendall($message,$new);
> }
> else {
> # Process socket
>
> $msg =getmsg($fh);
>
> print ">From $fh : $msg \n";
>
>
> # Maybe we have finished with the socket
> if ($msg eq "quit")
> {
> sendall("Closing ..",$fh);
> $sel->remove($fh);
> $fh->close;
> }
> elsif ($msg eq "run")
> {
> print "Running a process \n";
> #######Need to find ...
> }
> elsif ($msg eq "runprog")
> {
> print "Running a process \n";
> #######Need to find ...
> }
>
> else
> {
> $msg= "Server :".$msg."\n";
> sendall($msg,$fh);
>
> }
> }
> }
> }
>
> sub sendall
> {
> my $msg = shift;
> my $wfh = shift;
> foreach($sel->can_write)
> {
> if ($_ eq $wfh)
> {
> syswrite($wfh, ":".$msg.":", length($msg))
> }
> }
> }
> sub getmsg
> {
> my ($handle) = @_;
> my $msg = "";
> my $in = "";
> do {
> $msg .= $in;
> $nread = sysread($handle, $in, 1024);
>
> } while ($nread == 1);
> return($msg);
>
> }
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email alerts & NEW webcam video instant
> messaging with Yahoo! Messenger.
> http://im.yahoo.com
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
>
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger.
http://im.yahoo.com
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin