diff --git a/exec.go b/exec.go index 83fcb15..2e0e0b1 100644 --- a/exec.go +++ b/exec.go @@ -359,18 +359,6 @@ func execHandle(bg bool) interp.ExecHandlerFunc { var j *job if bg { - var procAttr *syscall.SysProcAttr - if runtime.GOOS == "windows" { - procAttr = &syscall.SysProcAttr{ - CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP, - } - } else { - procAttr = &syscall.SysProcAttr{ - Setpgid: true, - } - } - cmd.SysProcAttr = procAttr - j = jobs.getLatest() j.setHandle(&cmd) err = j.start() diff --git a/execfile_unix.go b/execfile_unix.go index 3160b85..44f924a 100644 --- a/execfile_unix.go +++ b/execfile_unix.go @@ -4,8 +4,13 @@ package main import ( "os" + "syscall" ) +var bgProcAttr *syscall.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, +} + func findExecutable(path string, inPath, dirs bool) error { f, err := os.Stat(path) if err != nil { diff --git a/execfile_windows.go b/execfile_windows.go index 502a595..4b3feef 100644 --- a/execfile_windows.go +++ b/execfile_windows.go @@ -5,8 +5,13 @@ package main import ( "path/filepath" "os" + "syscall" ) +var bgProcAttr *syscall.SysProcAttr = &syscall.SysProcAttr{ + CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP, +} + func findExecutable(path string, inPath, dirs bool) error { nameExt := filepath.Ext(path) pathExts := filepath.SplitList(os.Getenv("PATHEXT")) diff --git a/job.go b/job.go index 13dfb8e..b706c72 100644 --- a/job.go +++ b/job.go @@ -43,6 +43,7 @@ func (j *job) start() error { } j.setHandle(&cmd) } + j.handle.SysProcAttr = bgProcAttr if !j.once { j.once = true