aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorleongross <[email protected]>2024-04-04 11:52:53 +0200
committerRon Evans <[email protected]>2024-06-06 16:24:33 +0200
commit3a8ef33c7201ae7cd85c3ce1d012ecb707e32f67 (patch)
treeb38da5bb585d4ed4c32bfe4fb97d2c8d21f0a50c
parent20b58a0128c685f2a2b3ac4f157a670f70eb5f44 (diff)
downloadtinygo-3a8ef33c7201ae7cd85c3ce1d012ecb707e32f67.tar.gz
tinygo-3a8ef33c7201ae7cd85c3ce1d012ecb707e32f67.zip
add FindProcess for posix
Signed-off-by: leongross <[email protected]>
-rw-r--r--src/os/exec.go7
-rw-r--r--src/os/exec_posix.go5
-rw-r--r--src/os/exec_test.go32
3 files changed, 43 insertions, 1 deletions
diff --git a/src/os/exec.go b/src/os/exec.go
index 4ae0a9b98..2adcf3c1b 100644
--- a/src/os/exec.go
+++ b/src/os/exec.go
@@ -58,7 +58,7 @@ type Process struct {
}
func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error) {
- return nil, &PathError{"fork/exec", name, ErrNotImplemented}
+ return nil, &PathError{Op: "fork/exec", Path: name, Err: ErrNotImplemented}
}
func (p *Process) Wait() (*ProcessState, error) {
@@ -77,3 +77,8 @@ func Ignore(sig ...Signal) {
// leave all the signals unaltered
return
}
+
+// Keep compatibility with golang and always succeed and return new proc with pid on Linux.
+func FindProcess(pid int) (*Process, error) {
+ return findProcess(pid)
+}
diff --git a/src/os/exec_posix.go b/src/os/exec_posix.go
index 3ccb6963b..84843a281 100644
--- a/src/os/exec_posix.go
+++ b/src/os/exec_posix.go
@@ -19,3 +19,8 @@ var (
Interrupt Signal = syscall.SIGINT
Kill Signal = syscall.SIGKILL
)
+
+// Keep compatible with golang and always succeed and return new proc with pid on Linux.
+func findProcess(pid int) (*Process, error) {
+ return &Process{Pid: pid}, nil
+}
diff --git a/src/os/exec_test.go b/src/os/exec_test.go
new file mode 100644
index 000000000..032763abf
--- /dev/null
+++ b/src/os/exec_test.go
@@ -0,0 +1,32 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package os_test
+
+import (
+ . "os"
+ "runtime"
+ "testing"
+)
+
+func TestFindProcess(t *testing.T) {
+ // 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
+ proc, err := FindProcess(0)
+ if err != nil {
+ 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)
+ }
+ }
+
+}