update godeps

master
codeskyblue 8 years ago
parent 52ac079b7b
commit 0705305a4d

4
Godeps/Godeps.json generated

@ -13,8 +13,8 @@
"Rev": "33e0aa1cb7c019ccc3fbe049a8262a6403d30504"
},
{
"ImportPath": "github.com/codeskyblue/kproc",
"Rev": "ded6d6ad96cefa26886dd2ebd1a61f9252a4bbd0"
"ImportPath": "github.com/codeskyblue/kexec",
"Rev": "b7e1983cb3267c8862794eacf39b14386dfa441f"
},
{
"ImportPath": "github.com/golang/protobuf/proto",

@ -0,0 +1,39 @@
# kexec
[![GoDoc](https://godoc.org/github.com/codeskyblue/kexec?status.svg)](https://godoc.org/github.com/codeskyblue/kexec)
This is a golang lib, add a `Terminate` command to exec.
Tested on _windows, linux, darwin._
This lib has been used in [fswatch](https://github.com/codeskyblue/fswatch).
## Usage
go get -v github.com/codeskyblue/kexec
example1:
package main
import "github.com/codeskyblue/kexec"
func main(){
p := kexec.Command("python", "flask_main.py")
p.Start()
p.Terminate(syscall.SIGINT)
}
example2: see more [examples](examples)
package main
import "github.com/codeskyblue/kexec"
func main() {
// In unix will call: bash -c "python flask_main.py"
// In windows will call: cmd /c "python flask_main.py"
p := kexec.CommandString("python flask_main.py")
p.Start()
p.Terminate(syscall.SIGKILL)
}

@ -0,0 +1,19 @@
package main
import (
"log"
"syscall"
"time"
"github.com/codeskyblue/kexec"
)
func main() {
p := kexec.CommandString("python flask_main.py")
p.Start()
time.Sleep(3 * time.Second)
err := p.Terminate(syscall.SIGKILL)
if err != nil {
log.Println(err)
}
}

@ -0,0 +1,6 @@
import flask
app = flask.Flask(__name__)
if __name__ == '__main__':
app.run(port=46732, debug=True)

@ -0,0 +1,7 @@
package kexec
import "os/exec"
type KCommand struct {
*exec.Cmd
}

@ -1,9 +1,8 @@
// +build !windows
package kproc
package kexec
import (
"log"
"os"
"os/exec"
"syscall"
@ -14,30 +13,31 @@ func setupCmd(cmd *exec.Cmd) {
cmd.SysProcAttr.Setsid = true
}
func ProcCommand(cmd *exec.Cmd) *Process {
func Command(name string, arg ...string) *KCommand {
cmd := exec.Command(name, arg...)
setupCmd(cmd)
return &Process{
return &KCommand{
Cmd: cmd,
}
}
func ProcString(command string) *Process {
func CommandString(command string) *KCommand {
cmd := exec.Command("/bin/bash", "-c", command)
setupCmd(cmd)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return &Process{
return &KCommand{
Cmd: cmd,
}
}
func (p *Process) Terminate(sig os.Signal) (err error) {
func (p *KCommand) Terminate(sig os.Signal) (err error) {
if p.Process == nil {
return
}
// find pgid, ref: http://unix.stackexchange.com/questions/14815/process-descendants
group, err := os.FindProcess(-1 * p.Process.Pid)
log.Println(group)
//log.Println(group)
if err == nil {
err = group.Signal(sig)
}

@ -1,4 +1,4 @@
package kproc
package kexec
import (
"os"
@ -6,22 +6,22 @@ import (
"strconv"
)
func ProcCommand(cmd *exec.Cmd) *Process {
return &Process{
Cmd: cmd,
func Command(name string, arg ...string) *KCommand {
return &KCommand{
Cmd: exec.Command(name, arg...),
}
}
func ProcString(command string) *Process {
func CommandString(command string) *KCommand {
cmd := exec.Command("cmd", "/c", command)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return &Process{
return &KCommand{
Cmd: cmd,
}
}
func (p *Process) Terminate(sig os.Signal) (err error) {
func (p *KCommand) Terminate(sig os.Signal) (err error) {
if p.Process == nil {
return nil
}

@ -1,30 +0,0 @@
# kproc
[![GoDoc](https://godoc.org/github.com/codeskyblue/kproc?status.svg)](https://godoc.org/github.com/codeskyblue/kproc)
# Now have been moved to [kexec](https://github.com/codeskyblue/kexec)
This lib is not maintained any more. **!!!**
----------
This is a golang lib, offer a better way to kill all child process.
Tested on _windows, linux, darwin._
This lib has been used in [fswatch](https://github.com/codeskyblue/fswatch).
## Usage
go get -v github.com/codeskyblue/kproc
example:
func main() {
p := kproc.ProcString("python flask_main.py")
p.Start()
time.Sleep(3 * time.Second)
err := p.Terminate(syscall.SIGKILL)
if err != nil {
log.Println(err)
}
}

@ -1,7 +0,0 @@
package kproc
import "os/exec"
type Process struct {
*exec.Cmd
}
Loading…
Cancel
Save