mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-17 03:03:27 +00:00
Add process.Release for unix
Signed-off-by: leongross <leon.gross@9elements.com>
This commit is contained in:
@@ -62,6 +62,9 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Wait() (*ProcessState, error) {
|
func (p *Process) Wait() (*ProcessState, error) {
|
||||||
|
if p.Pid == -1 {
|
||||||
|
return nil, syscall.EINVAL
|
||||||
|
}
|
||||||
return nil, ErrNotImplemented
|
return nil, ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +81,13 @@ func Ignore(sig ...Signal) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Release releases any resources associated with the Process p,
|
||||||
|
// rendering it unusable in the future.
|
||||||
|
// Release only needs to be called if Wait is not.
|
||||||
|
func (p *Process) Release() error {
|
||||||
|
return p.release()
|
||||||
|
}
|
||||||
|
|
||||||
// Keep compatibility with golang and always succeed and return new proc with pid on Linux.
|
// Keep compatibility with golang and always succeed and return new proc with pid on Linux.
|
||||||
func FindProcess(pid int) (*Process, error) {
|
func FindProcess(pid int) (*Process, error) {
|
||||||
return findProcess(pid)
|
return findProcess(pid)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
package os
|
package os
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,3 +25,11 @@ var (
|
|||||||
func findProcess(pid int) (*Process, error) {
|
func findProcess(pid int) (*Process, error) {
|
||||||
return &Process{Pid: pid}, nil
|
return &Process{Pid: pid}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Process) release() error {
|
||||||
|
// NOOP for unix.
|
||||||
|
p.Pid = -1
|
||||||
|
// no need for a finalizer anymore
|
||||||
|
runtime.SetFinalizer(p, nil)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
+12
-15
@@ -12,21 +12,18 @@ import (
|
|||||||
|
|
||||||
func TestFindProcess(t *testing.T) {
|
func TestFindProcess(t *testing.T) {
|
||||||
// NOTE: For now, we only test the Linux case since only exec_posix.go is currently the only implementation.
|
// NOTE: For now, we only test the Linux case since only exec_posix.go is currently the only implementation.
|
||||||
if runtime.GOOS == "linux" {
|
// Linux guarantees that there is pid 0
|
||||||
// Linux guarantees that there is pid 0
|
proc, err := FindProcess(0)
|
||||||
proc, err := FindProcess(0)
|
if err != nil {
|
||||||
if err != nil {
|
t.Error("FindProcess(0): wanted err == nil, got %v:", err)
|
||||||
t.Error("FindProcess(0): wanted err == nil, got %v:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if proc.Pid != 0 {
|
|
||||||
t.Error("Expected pid 0, got: ", proc.Pid)
|
|
||||||
}
|
|
||||||
|
|
||||||
pid0 := Process{Pid: 0}
|
|
||||||
if *proc != pid0 {
|
|
||||||
t.Error("Expected &Process{Pid: 0}, got", *proc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if proc.Pid != 0 {
|
||||||
|
t.Error("Expected pid 0, got: ", proc.Pid)
|
||||||
|
}
|
||||||
|
|
||||||
|
pid0 := Process{Pid: 0}
|
||||||
|
if *proc != pid0 {
|
||||||
|
t.Error("Expected &Process{Pid: 0}, got", *proc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user