1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
'\" t
.\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.TH tcgetpgrp 3 2023-10-31 "Linux man-pages 6.06"
.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)
|