github.com/hashicorp/go-plugin@v1.6.0/internal/cmdrunner/process_windows.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package cmdrunner
     5  
     6  import (
     7  	"syscall"
     8  )
     9  
    10  const (
    11  	// Weird name but matches the MSDN docs
    12  	exit_STILL_ACTIVE = 259
    13  
    14  	processDesiredAccess = syscall.STANDARD_RIGHTS_READ |
    15  		syscall.PROCESS_QUERY_INFORMATION |
    16  		syscall.SYNCHRONIZE
    17  )
    18  
    19  // _pidAlive tests whether a process is alive or not
    20  func _pidAlive(pid int) bool {
    21  	h, err := syscall.OpenProcess(processDesiredAccess, false, uint32(pid))
    22  	if err != nil {
    23  		return false
    24  	}
    25  	defer syscall.CloseHandle(h)
    26  
    27  	var ec uint32
    28  	if e := syscall.GetExitCodeProcess(h, &ec); e != nil {
    29  		return false
    30  	}
    31  
    32  	return ec == exit_STILL_ACTIVE
    33  }