How can i use syscall.Kill in windows?


(shubham jain) #1

i need to kill child and parrent process using syscall.Kill.

when i am using syscall.Kill in windows, getting erorr : “undefined: syscall.Kill”


(Jay Ts) #2

The syscall package is dependent on the operating system. syscall.Kill is for Unix/Linux/Mac systems, not Windows.

Use godoc syscall to get information on the syscall package for your system. This is explained in the Overview section in the package documentation:

https://golang.org/pkg/syscall/


(shubham jain) #3

docs is too lengthy, could you please tell me for signal kill for windows platform.

like linux we can send signal to process through pkill command, in windows, is there any alternate ?


(Ignacio Gómez) #4

The overview section also states that the syscall package is deprecated:

Deprecated: this package is locked down. Callers should use the corresponding package in the golang.org/x/sys repository instead. That is also where updates required by new systems or versions should be applied. See https://golang.org/s/go1.4-syscall for more information.

So check here instead.


(Abhay Anoop) #5

Hi Shubham,

Is it necessary you have to use the syscall package?

If not, use github.com/shirou/gopsutil/process

Then,

p, err := process.NewProcess(pid) // Specify process id of parent
// handle error

for _, v := range p.Children(){
    err = *v.Kill()  // Kill each child
    // handle error
}

p.Kill() // Kill the parent process

Hope this clears it