Ejemplo n.º 1
0
func main() {
	flag.Parse()

	pid, err := readIntFromFile("pid")
	if err != nil {
		fmt.Fprintf(os.Stderr, "error reading pid: %v\n", err)
		os.Exit(254)
	}

	process, err := process.NewProcess(pid)
	if err != nil {
		fmt.Fprintf(os.Stderr, "unable to create process %d instance: %v\n", pid, err)
		os.Exit(254)
	}

	if force {
		if process.Kill() != nil {
			fmt.Fprintf(os.Stderr, "unable to kill process %d: %v\n", pid, err)
			os.Exit(254)
		}
	} else {
		if process.Terminate() != nil {
			fmt.Fprintf(os.Stderr, "unable to terminate process %d: %v\n", pid, err)
			os.Exit(254)
		}
	}
}
Ejemplo n.º 2
0
Archivo: stop.go Proyecto: nak3/rkt
func main() {
	flag.Parse()

	pid, err := readIntFromFile("ppid")
	if err != nil {
		fmt.Fprintf(os.Stderr, "error reading pid: %v\n", err)
		os.Exit(1)
	}

	process, err := process.NewProcess(pid)
	if err != nil {
		fmt.Fprintf(os.Stderr, "unable to create process %d instance: %v\n", pid, err)
		os.Exit(1)
	}

	if force {
		children, err := process.Children()
		if err != nil {
			fmt.Fprintf(os.Stderr, "cannot get child processes from %d: %v\n", pid, err)
			os.Exit(1)
		}

		for _, child := range children {
			if err := child.Kill(); err != nil {
				fmt.Fprintf(os.Stderr, "unable to kill process %d: %v\n", child.Pid, err)
				os.Exit(1)
			}
		}

		if err := process.Kill(); err != nil {
			fmt.Fprintf(os.Stderr, "unable to kill process %d: %v\n", pid, err)
			os.Exit(1)
		}
	} else {
		if process.Terminate() != nil {
			fmt.Fprintf(os.Stderr, "unable to terminate process %d: %v\n", pid, err)
			os.Exit(1)
		}
	}
}