Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Kill a perl script execution in windows

by nikosv (Hermit)
on Feb 18, 2013 at 12:32 UTC ( #1019333=note: print w/ replies, xml ) Need Help??


in reply to Kill a perl script execution in windows

You can use named events. They are kernel events so they persist across processes. You create the event in the first script and when the latter script loads you check for the event's existance. If it already exists then you know that there is another instance already loaded. Check Win32::Event

$event = Win32::Event->new([$manual, [$initial, [$name]]]) Constructor for a new event object. If $manual is true, you must manua +lly reset the event after it is signalled (the default is false). If +$initial is true, the initial state of the object is signalled (defau +lt false). If $name is omitted or undef, creates an unnamed event obj +ect. If $name signifies an existing event object, then $manual and $initial + are ignored and the object is opened. If this happens, $^E will be s +et to 183 (ERROR_ALREADY_EXISTS).


Comment on Re: Kill a perl script execution in windows
Download Code
Re^2: Kill a perl script execution in windows
by BrowserUk (Pope) on Feb 18, 2013 at 13:44 UTC

    That's good for preventing a second copy from starting; but not so useful for killing the previous version if it is running because it doesn't give you the pid.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      you don't need the PID. The first script waits for a signal to terminate as:
      use Win32::Event; use 5.010; $event = Win32::Event->new(1,0,"myevent"); while ($event->wait(0)==0) { say $i; print $i++; } say "exiting";
      or just $event->wait(), depends on the situation.Then the second one can signal it to abort :
      use Win32::Event; use 5.010; $event = Win32::Event->new(1,0,"myevent"); say $^E; $event->set;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019333]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2014-10-21 12:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (103 votes), past polls