Standard library / os
os.FindProcess()
Obtains a process handle for a PID. On Unix success alone does not establish that the PID exists. Avoid using arbitrary PIDs for signaling. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func FindProcess(pid int) (*Process, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| pid | int | Process ID. |
Return Value
(*Process, error)
Obtains a process handle for a PID.
Working Example
Example Snippetgo
package main
import ( "fmt" "os")
func must(e error) { if e != nil { panic(e) }}func main() { p, e := os.FindProcess(os.Getpid()) must(e) fmt.Println(p.Pid == os.Getpid()) must(p.Release())}