pkg.re/essentialkaos/ek.v11@v12.41.0+incompatible/pid/pid_darwin.go (about)

     1  package pid
     2  
     3  import (
     4  	"os"
     5  	"syscall"
     6  )
     7  
     8  // ////////////////////////////////////////////////////////////////////////////////// //
     9  //                                                                                    //
    10  //                         Copyright (c) 2022 ESSENTIAL KAOS                          //
    11  //      Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>     //
    12  //                                                                                    //
    13  // ////////////////////////////////////////////////////////////////////////////////// //
    14  
    15  // IsWorks returns true if process with PID from PID file is works
    16  func IsWorks(name string) bool {
    17  	pid := Get(name)
    18  
    19  	if pid == -1 {
    20  		return false
    21  	}
    22  
    23  	return IsProcessWorks(pid)
    24  }
    25  
    26  // IsProcessWorks returns true if process with given PID is works
    27  func IsProcessWorks(pid int) bool {
    28  	// On Unix systems, FindProcess always succeeds and returns a Process
    29  	// for the given pid, regardless of whether the process exists.
    30  	pr, _ := os.FindProcess(pid)
    31  	return pr.Signal(syscall.Signal(0)) == nil
    32  }