summaryrefslogtreecommitdiffstats
path: root/golib/eows/eows-signal.go
blob: 5db5366b0ce801f9d11d174160bd04d2b9e2c131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .g
// +build !windows

// Package eows is used to Execute commands Over WebSocket
package eows

import (
	"fmt"
	"os"
	"syscall"
)

// Signal sends a signal to the running command / process
func (e *ExecOverWS) Signal(signal string) error {
	var sig os.Signal
	switch signal {
	case "quit", "SIGQUIT":
		sig = syscall.SIGQUIT
	case "terminated", "SIGTERM":
		sig = syscall.SIGTERM
	case "interrupt", "SIGINT":
		sig = syscall.SIGINT
	case "aborted", "SIGABRT":
		sig = syscall.SIGABRT
	case "continued", "SIGCONT":
		sig = syscall.SIGCONT
	case "hangup", "SIGHUP":
		sig = syscall.SIGHUP
	case "killed", "SIGKILL":
		sig = syscall.SIGKILL
	case "stopped (signal)", "SIGSTOP":
		sig = syscall.SIGSTOP
	case "stopped", "SIGTSTP":
		sig = syscall.SIGTSTP
	case "user defined signal 1", "SIGUSR1":
		sig = syscall.SIGUSR1
	case "user defined signal 2", "SIGUSR2":
		sig = syscall.SIGUSR2
	default:
		return fmt.Errorf("Unsupported signal")
	}

	if e.proc == nil {
		return fmt.Errorf("Cannot retrieve process")
	}

	fmt.Printf("SEND signal %v to proc %v\n", sig, e.proc.Pid)
	return e.proc.Signal(sig)
}