Wireshark-dev: Re: [Wireshark-dev] buildbot down?

From: Graham Bloice <graham.bloice@xxxxxxxxxxxxx>
Date: Tue, 11 Apr 2017 10:03:30 +0100
For reference, the PowerShell equivalent, note that this will only attempt to stop a pid once, there may be multiple locking handles for a single pid:

# Stop-ProcessByFileLock
# Stops processes that have an open handle on the path fragment specified

param(
  [parameter(Mandatory=$true)]
  [string]$path
)

$processes = @{}
$handles = handle $path
foreach($line in $handles) {
  if ($line -match "(\S+)\s+pid: (\d*)") {
    $processes[$($Matches[1])] = $($Matches[2])
  }
}

foreach($process in $processes.GetEnumerator()) {
    Write-Host "Killing process $($process.Name) with pid:$($process.Value)"
    Stop-Process -Id $process.Value -Force
}



On 10 April 2017 at 21:36, Maynard, Chris <Christopher.Maynard@xxxxxxx> wrote:
Here's a batch file that *might* also help?  It makes use of both handle.exe and taskkill.exe to hopefully achieve what you're looking for?
 
:: Forcefully kills the process with the given open file containing the
:: specified pattern.  For example, running the following will kill the first
:: process found with a file open that contains the string "wireshark_pcapng"
:: anywhere in the name:
::
::     killprocbyfile.bat wireshark_pcapng
::
 
@ECHO OFF
 
IF ["%~1"] == [""] GOTO USAGE
 
@ECHO OFF
FOR /F "TOKENS=1-3 USEBACKQ" %%I IN (`HANDLE.EXE "%1"`) DO (
    IF "%%J" == "pid:" (
        ECHO Killing %%I PID: %%K
        TASKKILL.EXE /F /PID %%K
        GOTO :EOF
    ) 
)
GOTO :EOF
 
:USAGE
ECHO Usage: %~0 ^<pattern^>
 
- Chris
 
> -----Original Message-----
> bounces@xxxxxxxxxxxxx] On Behalf Of Maynard, Chris
> Sent: Monday, April 10, 2017 2:12 PM
> To: Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx>
> Subject: Re: [Wireshark-dev] buildbot down?
>
> Would taskkill.exe help?
>
> For example, "taskkill.exe /im dumpcap.exe" , etc.
>
> I've also used WMIC in the past to save ProcessID's of tasks so you can later kill
> specific instances of a task instead of all of them with the same name.  I'd refer
> you to the dumpcap.bat file posted on https://wiki.wireshark.org/Tools for how
> I did that.
>
> - Chris
> [1]:
> s/en-us/taskkill.mspx?mfr=true
>
> - Chris
>
> > -----Original Message-----
> > bounces@xxxxxxxxxxxxx] On Behalf Of Gerald Combs
> > Sent: Monday, April 10, 2017 2:06 PM
> > To: Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx>
> > Subject: Re: [Wireshark-dev] buildbot down?
> >
> > On 4/9/17 1:23 AM, Graham Bloice wrote:
> > >
> > >
> > > On 9 April 2017 at 01:54, Gerald Combs <gerald@xxxxxxxxxxxxx
> > >
> > >     On 4/8/17 10:47 AM, Peter Wu wrote:
> > >     >
> > >     > There is another problem though with the Petri-Dish builder, a previous
> > >     > build on the Petri-Dish Windows x86 builder failed and left a process on
> > >     > the machine, breaking all following builds. Gerald, can you have a look?
> > >
> > >     It's back up.
> > >
> > >     > Maybe it is an idea to add a pass that kills all
> > >     > dumpcap/tshark/wireshark processes before starting the build?
> > (Assuming
> > >     > that no other builds happen in parallel).
> > >
> > >     Is there a straightforward equivalent to "kill -9 $( lsof -t
> > >     /path/to/buildbot )" on Windows?
> > >
> > >
> > > Difficult to identify which process you want to kill with
> > > Stop-Process.  With PS 4.0 and later you can run ((Get-Process
> > > -IncludeUserName).where({$_.username -AND $_.username -notmatch
> > > "^NT"})) to get the processes owned by the user account running the
> > > command, but there's still too many in there that shouldn't be stopped.
> > >
> > > Maybe Get-Process | Where-Object -Property ProcessName -match
> > > ".*(Process1|Process2|Process3).*" | Stop-Process would do if the
> > > number of processes to look for isn't too bad.
> >
> > How difficult would it be to parse the output of the Sysinternals
> > "Handle" utility in PS? That would presumably tell us which process
> > has the build directory locked while limiting the risk of clobbering
> > any other Buildbot instances that happen to be running.
> >
> ________________________________________________________________
> > ___________
> > Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
> >
> CONFIDENTIALITY NOTICE: This message is the property of International Game
> Technology PLC and/or its subsidiaries and may contain proprietary,
> confidential or trade secret information.  This message is intended solely for
> the use of the addressee.  If you are not the intended recipient and have
> received this message in error, please delete this message from your system.
> Any unauthorized reading, distribution, copying, or other use of this message or
> its attachments is strictly prohibited.
>
> ________________________________________________________________
> ___________
> Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
 

CONFIDENTIALITY NOTICE: This message is the property of International Game Technology PLC and/or its subsidiaries and may contain proprietary, confidential or trade secret information.  This message is intended solely for the use of the addressee.  If you are not the intended recipient and have received this message in error, please delete this message from your system. Any unauthorized reading, distribution, copying, or other use of this message or its attachments is strictly prohibited.


___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://www.wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request@wireshark.org?subject=unsubscribe



--
Graham Bloice