cmd/gitbay-runner/proc_unix.go

4a511e42574ead9c92dc73fd320f296cc4dbea07
gitbay/cmd/gitbay-runner/proc_unix.go

29 lines · 737 bytes

2 symbols in this file
 1//go:build unix
 2
 3package main
 4
 5import (
 6	"os/exec"
 7	"syscall"
 8)
 9
10// A step runs as its own process group, so ending it ends everything it
11// started. Killing only the shell leaves its children alive and holding
12// the log pipe, and a wait on that pipe lasts as long as the longest
13// child: dash forks a single command rather than exec'ing it, so on a
14// Debian host "sh -c 'sleep 120'" survived its shell by two minutes.
15func ownProcessGroup(cmd *exec.Cmd) {
16	if cmd.SysProcAttr == nil {
17		cmd.SysProcAttr = &syscall.SysProcAttr{}
18	}
19	cmd.SysProcAttr.Setpgid = true
20}
21
22func killTree(cmd *exec.Cmd) {
23	if cmd.Process == nil {
24		return
25	}
26	if err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL); err != nil {
27		cmd.Process.Kill()
28	}
29}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form