Hilbish/job_unix.go

39 lines
616 B
Go
Raw Normal View History

2024-06-09 09:35:16 +00:00
// +build unix
package main
import (
"errors"
"os"
"syscall"
"golang.org/x/sys/unix"
)
func (j *job) foreground() error {
if jobs.foreground {
return errors.New("(another) job already foregrounded")
}
pgid, _ := syscall.Getpgid(j.pid)
// tcsetpgrp
unix.IoctlSetPointerInt(0, unix.TIOCSPGRP, pgid)
proc, _ := os.FindProcess(j.pid)
proc.Wait()
hshPgid, _ := syscall.Getpgid(os.Getpid())
unix.IoctlSetPointerInt(0, unix.TIOCSPGRP, hshPgid)
return nil
}
func (j *job) background() error {
proc := j.handle.Process
if proc == nil {
return nil
}
proc.Signal(syscall.SIGCONT)
return nil
}