Golang processes: Difference between revisions
From wikinotes
Line 12: | Line 12: | ||
<blockquote> | <blockquote> | ||
<syntaxhighlight lang="go"> | <syntaxhighlight lang="go"> | ||
import "os" | |||
import "os/user" | |||
os.Executable() | os.Executable() | ||
os.Getpid() | os.Getpid() | ||
Line 17: | Line 20: | ||
os.Getuid() | os.Getuid() | ||
os.Getgid() | os.Getgid() | ||
os.Exit(0) // exit process with exitcode '1' | |||
// environment | |||
envvars := os.Environ() // ["FOO=bar", "BAR=baz", ...] | envvars := os.Environ() // ["FOO=bar", "BAR=baz", ...] | ||
pwd, err := os.Getwd() // get current pwd/cwd | pwd, err := os.Getwd() // get current pwd/cwd | ||
user.Current() // 'will' | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Current Process --> | </blockquote><!-- Current Process --> |
Revision as of 13:29, 18 June 2022
Documentation
os
https://pkg.go.dev/os@go1.18.3
Current Process
import "os" import "os/user" os.Executable() os.Getpid() os.Getppid() os.Getuid() os.Getgid() os.Exit(0) // exit process with exitcode '1' // environment envvars := os.Environ() // ["FOO=bar", "BAR=baz", ...] pwd, err := os.Getwd() // get current pwd/cwd user.Current() // 'will'
Manage Processes
os.Process.FindProcess() os.Process.Kill() os.Process.Signal()
Subprocess
os.Process.StartProcess ProcAttr Process