-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap syscall.Kill to a wrapper to avoid error in Windows
syscall.Kill is a system library call not available in Windows making it difficult to compile the code as is in Windows and for proper IDE support. So wrapped syscall.Kill to a system specific build constrained implementation to avoid the compile error.
- Loading branch information
Showing
5 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package utils | ||
|
||
import "syscall" | ||
|
||
// ProcessKiller interface for killing a process | ||
type ProcessKiller interface { | ||
Kill(PID int, signal syscall.Signal) error | ||
} | ||
|
||
func NewProcessKiller() ProcessKiller { | ||
return &DefaultProcessKiller{} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build linux || darwin | ||
|
||
package utils | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
// DefaultProcessKiller is a default implementation of ProcessKiller interface | ||
type DefaultProcessKiller struct{} | ||
|
||
func (pk *DefaultProcessKiller) Kill(pid int, signal syscall.Signal) error { | ||
_, err := os.FindProcess(pid) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = syscall.Kill(pid, syscall.SIGINT) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build windows | ||
|
||
package utils | ||
|
||
import ( | ||
"syscall" | ||
) | ||
|
||
// DefaultProcessKiller is a default implementation of ProcessKiller interface | ||
type DefaultProcessKiller struct { | ||
} | ||
|
||
func (pk *DefaultProcessKiller) Kill(pid int, signal syscall.Signal) error { | ||
return nil | ||
} |