Last active
January 9, 2025 15:31
-
-
Save lee8oi/ec404fa99ea0f6efd9d1 to your computer and use it in GitHub Desktop.
Revisions
-
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 3 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,22 +18,11 @@ func Start(args ...string) (p *os.Process, err error) { return nil, err } func main() { if proc, err := Start("ping", "-c 3", "www.google.com"); err == nil { proc.Wait() } if proc, err := Start("zsh"); err == nil { proc.Wait() } } -
lee8oi renamed this gist
Mar 19, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 10 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,20 +3,19 @@ package main import ( "os" "os/exec" ) func Start(args ...string) (p *os.Process, err error) { if args[0], err = exec.LookPath(args[0]); err == nil { var procAttr os.ProcAttr procAttr.Files = []*os.File{os.Stdin, os.Stdout, os.Stderr} p, err := os.StartProcess(args[0], args, &procAttr) if err == nil { return p, nil } } return nil, err } func Wait(pid int) error { @@ -31,10 +30,10 @@ func Wait(pid int) error { } func main() { if proc, err := Start("ping", "-c 3", "www.google.com"); err == nil { Wait(proc.Pid) } if p, err := Start("zsh"); err == nil { Wait(p.Pid) } } -
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,10 +31,10 @@ func Wait(pid int) error { } func main() { if pid, err := Start("ping", "-c 3", "www.google.com"); err == nil { go Wait(pid) } if pid, err := Start("bash"); err == nil { Wait(pid) } } -
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,12 +27,14 @@ func Wait(pid int) error { return nil } } return err } func main() { if pid, err := Start("bash"); err == nil { Wait(pid) } if pid, err := Start("ping", "-c3", "www.google.com"); err == nil { Wait(pid) } } -
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,6 +31,8 @@ func Wait(pid int) error { } func main() { pid, _ := Start("bash") Wait(pid) pid, _ = Start("ping", "-c3", "www.google.com") Wait(pid) } -
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 6 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,27 +11,26 @@ func Start(args ...string) (pid int, err error) { var procAttr syscall.ProcAttr procAttr.Files = []uintptr{uintptr(syscall.Stdin), uintptr(syscall.Stdout), uintptr(syscall.Stderr)} p, err := syscall.ForkExec(args[0], args, &procAttr) if err == nil { return p, nil } } return 0, err } func Wait(pid int) error { proc, err := os.FindProcess(pid) if err == nil { ps, err := proc.Wait() if ps.Exited() && err == nil { return nil } } return (err) } func main() { pid, _ := Start("ping", "-c3", "www.google.com") Wait(pid) } -
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 7 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,20 +6,17 @@ import ( "syscall" ) func Start(args ...string) (pid int, err error) { if args[0], err = exec.LookPath(args[0]); err == nil { var procAttr syscall.ProcAttr procAttr.Files = []uintptr{uintptr(syscall.Stdin), uintptr(syscall.Stdout), uintptr(syscall.Stderr)} p, err := syscall.ForkExec(args[0], args[1:], &procAttr) if err == nil { return p, nil } } panic(err) return } @@ -35,6 +32,6 @@ func Wait(pid int) { } func main() { pid, _ := Start("bash") Wait(pid) } -
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,11 +26,9 @@ func Start(args ...string) (pid int) { func Wait(pid int) { proc, err := os.FindProcess(pid) if err == nil { ps, err := proc.Wait() if ps.Exited() && err == nil { return } } panic(err) -
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ package main import ( "os" "os/exec" "syscall" @@ -24,9 +23,7 @@ func Start(args ...string) (pid int) { return } func Wait(pid int) { proc, err := os.FindProcess(pid) if err == nil { for { @@ -38,3 +35,8 @@ func main() { } panic(err) } func main() { pid := Start("bash") Wait(pid) } -
lee8oi revised this gist
Mar 19, 2015 . 1 changed file with 11 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main import ( "fmt" "os" "os/exec" "syscall" ) @@ -26,6 +27,14 @@ func Start(args ...string) (pid int) { func main() { pid := Start("bash") fmt.Println(pid) proc, err := os.FindProcess(pid) if err == nil { for { ps, err := proc.Wait() if ps.Exited() && err == nil { return } } } panic(err) } -
lee8oi created this gist
Mar 19, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ package main import ( "fmt" "os/exec" "syscall" ) func Start(args ...string) (pid int) { if binary, lookErr := exec.LookPath(args[0]); lookErr == nil { args[0] = binary var procAttr syscall.ProcAttr procAttr.Files = []uintptr{uintptr(syscall.Stdin), uintptr(syscall.Stdout), uintptr(syscall.Stderr)} p, execErr := syscall.ForkExec(args[0], args[1:], &procAttr) if execErr != nil { panic(execErr) } pid = p } else { panic(lookErr) } return } func main() { pid := Start("bash") fmt.Println(pid) for { } }