mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
feat: add StartProcess, StopProcess, KillProcess for system package
This commit is contained in:
1 parent
3e1ac5e0b5
commit
e58c9b797b
5 files changed
+316
-15
No files matched your search
@@ -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>
|
||||
}
|
||||
Reference in new issue
Block a user