func (tg *ThreadGroup) SetForegroundProcessGroup(tty *TTY, pgid ProcessGroupID) (int32, error) {
	tty.mu.Lock()
	defer tty.mu.Unlock()

	tg.pidns.owner.mu.Lock()
	defer tg.pidns.owner.mu.Unlock()
	tg.signalHandlers.mu.Lock()
	defer tg.signalHandlers.mu.Unlock()

	// TODO(b/129283598): "If tcsetpgrp() is called by a member of a
	// background process group in its session, and the calling process is
	// not blocking or ignoring SIGTTOU, a SIGTTOU signal is sent to all
	// members of this background process group."

	// tty must be the controlling terminal.
	if tg.tty != tty {
		return -1, syserror.ENOTTY
	}

	// pgid must be positive.
	if pgid < 0 {
		return -1, syserror.EINVAL
	}

	// pg must not be empty. Empty process groups are removed from their
	// pid namespaces.
	pg, ok := tg.pidns.processGroups[pgid]
	if !ok {
		return -1, syserror.ESRCH
	}

	// pg must be part of this process's session.
	if tg.processGroup.session != pg.session {
		return -1, syserror.EPERM
	}

	tg.processGroup.session.foreground.id = pgid
	return 0, nil
}
// SetForegroundProcessGroup sets the foreground process group of tty to pgid.
SetForegroundProcessGroup sets the foreground process group of tty to pgid.
// SetForegroundProcessGroup sets the foreground process group of tty to pgid .
func (tg *ThreadGroup) SetForegroundProcessGroup(tty *TTY, pgid ProcessGroupID) (int32, error) {
	tty.mu.Lock()
	defer tty.mu.Unlock()
	tg.pidns.owner.mu.Lock()
	defer tg.pidns.owner.mu.Unlock()
	tg.signalHandlers.mu.Lock()
	defer tg.signalHandlers.mu.Unlock()
	if tg.tty != tty {
		return -1, syserror.ENOTTY
	}
	if pgid < 0 {
		return -1, syserror.EINVAL
	}
	pg, ok := tg.pidns.processGroups[pgid]
	if !ok {
		return -1, syserror.ESRCH
	}
	if tg.processGroup.session != pg.session {
		return -1, syserror.EPERM
	}
	tg.processGroup.session.foreground.id = pgid
	return 0, nil
}
func ( tg * ThreadGroup ) SetForegroundProcessGroup ( tty * TTY , pgid ProcessGroupID ) ( int32 , error ) { tty . mu . Lock ( ) defer tty . mu . Unlock ( ) tg . pidns . owner . mu . Lock ( ) defer tg . pidns . owner . mu . Unlock ( ) tg . signalHandlers . mu . Lock ( ) defer tg . signalHandlers . mu . Unlock ( ) if tg . tty != tty { return - 1 , syserror . ENOTTY } if pgid < 0 { return - 1 , syserror . EINVAL } pg , ok := tg . pidns . processGroups [ pgid ] if ! ok { return - 1 , syserror . ESRCH } if tg . processGroup . session != pg . session { return - 1 , syserror . EPERM } tg . processGroup . session . foreground . id = pgid return 0 , nil }
SetForegroundProcessGroup sets the foreground process group of tty to pgid.
SetForegroundProcessGroup sets the foreground process group of tty to pgid .
// TODO(b/129283598): "If tcsetpgrp() is called by a member of a // background process group in its session, and the calling process is // not blocking or ignoring SIGTTOU, a SIGTTOU signal is sent to all // members of this background process group." // tty must be the controlling terminal. // pgid must be positive. // pg must not be empty. Empty process groups are removed from their // pid namespaces. // pg must be part of this process's session.