1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 23:22:28 +08:00

feat: add StartProcess, StopProcess, KillProcess for system package

This commit is contained in:
dudaodong
2024-09-13 15:09:44 +08:00
parent 3e1ac5e0b5
commit e58c9b797b
5 changed files with 316 additions and 15 deletions

View File

@@ -1,6 +1,9 @@
package system
import "fmt"
import (
"fmt"
"time"
)
func ExampleSetOsEnv() {
err := SetOsEnv("foo", "abc")
@@ -75,3 +78,42 @@ func ExampleGetOsBits() {
// Output:
// 64
}
func ExampleStartProcess() {
pid, err := StartProcess("sleep", "2")
if err != nil {
return
}
fmt.Println(pid)
}
func ExampleStopProcess() {
pid, err := StartProcess("sleep", "10")
if err != nil {
return
}
time.Sleep(1 * time.Second)
err = StopProcess(pid)
fmt.Println(err)
// Output:
// <nil>
}
func ExampleKillProcess() {
pid, err := StartProcess("sleep", "3")
if err != nil {
return
}
time.Sleep(1 * time.Second)
err = KillProcess(pid)
fmt.Println(err)
// Output:
// <nil>
}