signal

package
v12.122.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Overview

Package signal provides methods for handling POSIX signals

Index

Examples

Constants

View Source
const (
	ABRT   = syscall.SIGABRT   // ABRT signal code
	ALRM   = syscall.SIGALRM   // ALRM signal code
	BUS    = syscall.SIGBUS    // BUS signal code
	CHLD   = syscall.SIGCHLD   // CHLD signal code
	CONT   = syscall.SIGCONT   // CONT signal code
	FPE    = syscall.SIGFPE    // FPE signal code
	HUP    = syscall.SIGHUP    // HUP signal code
	ILL    = syscall.SIGILL    // ILL signal code
	INT    = syscall.SIGINT    // INT signal code
	IO     = syscall.SIGIO     // IO signal code
	IOT    = syscall.SIGIOT    // IOT signal code
	KILL   = syscall.SIGKILL   // KILL signal code
	PIPE   = syscall.SIGPIPE   // PIPE signal code
	PROF   = syscall.SIGPROF   // PROF signal code
	QUIT   = syscall.SIGQUIT   // QUIT signal code
	SEGV   = syscall.SIGSEGV   // SEGV signal code
	STOP   = syscall.SIGSTOP   // STOP signal code
	SYS    = syscall.SIGSYS    // SYS signal code
	TERM   = syscall.SIGTERM   // TERM signal code
	TRAP   = syscall.SIGTRAP   // TRAP signal code
	TSTP   = syscall.SIGTSTP   // TSTP signal code
	TTIN   = syscall.SIGTTIN   // TTIN signal code
	TTOU   = syscall.SIGTTOU   // TTOU signal code
	URG    = syscall.SIGURG    // URG signal code
	USR1   = syscall.SIGUSR1   // USR1 signal code
	USR2   = syscall.SIGUSR2   // USR2 signal code
	VTALRM = syscall.SIGVTALRM // VTALRM signal code
	WINCH  = syscall.SIGWINCH  // WINCH signal code
	XCPU   = syscall.SIGXCPU   // XCPU signal code
	XFSZ   = syscall.SIGXFSZ   // XFSZ signal code
)

Signal codes

Variables

This section is empty.

Functions

func GetByCode

func GetByCode(code int) (syscall.Signal, error)

GetByCode returns signal with given code

func GetByName

func GetByName(name string) (syscall.Signal, error)

GetByName returns signal with given name

func Send

func Send(pid int, signal syscall.Signal) error

Send sends given signal to process

Types

type Handlers

type Handlers map[os.Signal]func()

Handlers is map signal → handler

func (Handlers) Track

func (h Handlers) Track()

Track catches signal and executes handler for this signal

Example
hupHandler := func() {
	fmt.Println("Got HUP signal")
}

usr1Handler := func() {
	fmt.Println("Got USR1 signal")
}

Handlers{
	HUP:  hupHandler,
	USR1: usr1Handler,
}.Track()
Output:

func (Handlers) TrackAsync

func (h Handlers) TrackAsync()

TrackAsync catches signal and executes async handler for this signal

Example
hupHandler := func() {
	fmt.Println("Got HUP signal")
}

usr1Handler := func() {
	fmt.Println("Got USR1 signal")
}

Handlers{
	HUP:  hupHandler,
	USR1: usr1Handler,
}.TrackAsync()

time.Sleep(time.Hour)
Output:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL