Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Kill a perl script execution in windows

by nikosv (Chaplain)
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).

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019333]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-06-22 04:18 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (121 votes). Check out past polls.