implements Process.Send_signal() and other signal functions on posix.

pull/4/head
Shirou WAKAYAMA
parent 9ae9ff1bce
commit d1b1221e7f

@ -92,6 +92,11 @@ Current Status
- memory_info_ex (linux)
- Memory_maps() (linux) <- this is a function
- open_files (linux)
- send_signal (linux, freebsd)
- suspend (linux, freebsd)
- resume (linux, freebsd)
- terminate (linux, freebsd)
- kill (linux, freebsd)
- not yet
@ -125,11 +130,6 @@ Current Status
- parent (use ppid instead)
- as_dict
- send_signal()
- suspend()
- resume()
- terminate()
- kill()
- wait

@ -4,6 +4,8 @@ package gopsutil
import (
"os"
"os/exec"
"strconv"
"strings"
"syscall"
)
@ -45,3 +47,39 @@ func getTerminalMap() (map[uint64]string, error) {
}
return ret, nil
}
func (p *Process) Send_signal(sig syscall.Signal) error {
sig_as_str := "INT"
switch sig {
case syscall.SIGSTOP:
sig_as_str = "STOP"
case syscall.SIGCONT:
sig_as_str = "CONT"
case syscall.SIGTERM:
sig_as_str = "TERM"
case syscall.SIGKILL:
sig_as_str = "KILL"
}
cmd := exec.Command("kill", "-s", sig_as_str, strconv.Itoa(int(p.Pid)))
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}
return nil
}
func (p *Process) Suspend() error {
return p.Send_signal(syscall.SIGSTOP)
}
func (p *Process) Resume() error {
return p.Send_signal(syscall.SIGCONT)
}
func (p *Process) Terminate() error {
return p.Send_signal(syscall.SIGTERM)
}
func (p *Process) Kill() error {
return p.Send_signal(syscall.SIGKILL)
}

@ -6,6 +6,7 @@ import (
"os"
"runtime"
"testing"
"syscall"
)
func Test_Pids(t *testing.T) {
@ -65,3 +66,14 @@ func Test_Process_memory_maps(t *testing.T) {
}
}
func Test_SendSignal(t *testing.T){
check_pid := os.Getpid()
p, _ := NewProcess(int32(check_pid))
err := p.Send_signal(syscall.SIGCONT)
if err != nil{
t.Errorf("send signal %v", err)
}
}

Loading…
Cancel
Save