-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sir Darkrengarius
authored and
Sir Darkrengarius
committed
Oct 10, 2019
1 parent
8104ad3
commit 1fe21cb
Showing
23 changed files
with
790 additions
and
187 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package appserver | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"sync" | ||
"syscall" | ||
) | ||
|
||
type ProcManager struct { | ||
processes []*os.Process | ||
mu sync.Mutex | ||
} | ||
|
||
func NewProcManager() *ProcManager { | ||
return &ProcManager{processes: make([]*os.Process, 0)} | ||
} | ||
|
||
func (m *ProcManager) Start(cmd *exec.Cmd) (int, error) { | ||
if err := cmd.Start(); err != nil { | ||
return -1, err | ||
} | ||
m.mu.Lock() | ||
m.processes = append(m.processes, cmd.Process) | ||
m.mu.Unlock() | ||
|
||
return cmd.Process.Pid, nil | ||
} | ||
|
||
func (m *ProcManager) Stop(pid int) (err error) { | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
|
||
for _, process := range m.processes { | ||
if process.Pid != pid { | ||
continue | ||
} | ||
|
||
if sigErr := process.Signal(syscall.SIGKILL); sigErr != nil && err == nil { | ||
err = sigErr | ||
} | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (m *ProcManager) Wait(cmd *exec.Cmd) error { | ||
return cmd.Wait() | ||
} |
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
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
Oops, something went wrong.