| '\" t |
| .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl> |
| .\" |
| .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| .\" |
| .TH tcgetpgrp 3 (date) "Linux man-pages (unreleased)" |
| .SH NAME |
| tcgetpgrp, tcsetpgrp \- get and set terminal foreground process group |
| .SH LIBRARY |
| Standard C library |
| .RI ( libc ,\~ \-lc ) |
| .SH SYNOPSIS |
| .nf |
| .B "#include <unistd.h>" |
| .P |
| .BI "pid_t tcgetpgrp(int " fd ); |
| .BI "int tcsetpgrp(int " fd ", pid_t " pgrp ); |
| .fi |
| .SH DESCRIPTION |
| The function |
| .BR tcgetpgrp () |
| returns the process group ID of the foreground process group on the |
| terminal associated to |
| .IR fd , |
| which must be the controlling terminal of the calling process. |
| .\" The process itself may be a background process. |
| .P |
| The function |
| .BR tcsetpgrp () |
| makes the process group with process group ID |
| .I pgrp |
| the foreground process group on the terminal associated to |
| .IR fd , |
| which must be the controlling terminal of the calling process, |
| and still be associated with its session. |
| Moreover, |
| .I pgrp |
| must be a (nonempty) process group belonging to |
| the same session as the calling process. |
| .P |
| If |
| .BR tcsetpgrp () |
| is called by a member of a background process group in its session, |
| and the calling process is not blocking or ignoring |
| .BR SIGTTOU , |
| a |
| .B SIGTTOU |
| signal is sent to all members of this background process group. |
| .SH RETURN VALUE |
| When |
| .I fd |
| refers to the controlling terminal of the calling process, |
| the function |
| .BR tcgetpgrp () |
| will return the foreground process group ID of that terminal |
| if there is one, and some value larger than 1 that is not |
| presently a process group ID otherwise. |
| When |
| .I fd |
| does not refer to the controlling terminal of the calling process, |
| \-1 is returned, and |
| .I errno |
| is set to indicate the error. |
| .P |
| When successful, |
| .BR tcsetpgrp () |
| returns 0. |
| Otherwise, it returns \-1, and |
| .I errno |
| is set to indicate the error. |
| .SH ERRORS |
| .TP |
| .B EBADF |
| .I fd |
| is not a valid file descriptor. |
| .TP |
| .B EINVAL |
| .I pgrp |
| has an unsupported value. |
| .TP |
| .B ENOTTY |
| The calling process does not have a controlling terminal, or |
| it has one but it is not described by |
| .IR fd , |
| or, for |
| .BR tcsetpgrp (), |
| this controlling terminal is no longer associated with the session |
| of the calling process. |
| .TP |
| .B EPERM |
| .I pgrp |
| has a supported value, but is not the process group ID of a |
| process in the same session as the calling process. |
| .SH ATTRIBUTES |
| For an explanation of the terms used in this section, see |
| .BR attributes (7). |
| .TS |
| allbox; |
| lbx lb lb |
| l l l. |
| Interface Attribute Value |
| T{ |
| .na |
| .nh |
| .BR tcgetpgrp (), |
| .BR tcsetpgrp () |
| T} Thread safety MT-Safe |
| .TE |
| .SH VERSIONS |
| These functions are implemented via the |
| .B TIOCGPGRP |
| and |
| .B TIOCSPGRP |
| ioctls. |
| .SH STANDARDS |
| POSIX.1-2008. |
| .SH HISTORY |
| POSIX.1-2001. |
| .P |
| The ioctls appeared in 4.2BSD. |
| The functions are POSIX inventions. |
| .SH SEE ALSO |
| .BR setpgid (2), |
| .BR setsid (2), |
| .BR credentials (7) |