xref: /freebsd/lib/libsys/getpgrp.2 (revision a91a246563dffa876a52f53a98de4af9fa364c52)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd June 4, 1993
29.Dt GETPGRP 2
30.Os
31.Sh NAME
32.Nm getpgrp
33.Nd get process group
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In unistd.h
38.Ft pid_t
39.Fn getpgrp void
40.Ft pid_t
41.Fn getpgid "pid_t pid"
42.Sh DESCRIPTION
43The process group of the current process is returned by
44.Fn getpgrp .
45The process group of the process identified by
46.Fa pid
47is returned by
48.Fn getpgid .
49If
50.Fa pid
51is zero,
52.Fn getpgid
53returns the process group of the current process.
54.Pp
55Process groups are used for distribution of signals, and
56by terminals to arbitrate requests for their input: processes
57that have the same process group as the terminal are foreground
58and may read, while others will block with a signal if they attempt
59to read.
60.Pp
61This system call is thus used by programs such as
62.Xr csh 1
63to create
64process groups
65in implementing job control.
66The
67.Fn tcgetpgrp
68and
69.Fn tcsetpgrp
70calls
71are used to get/set the process group of the control terminal.
72.Sh RETURN VALUES
73The
74.Fn getpgrp
75system call always succeeds.
76Upon successful completion, the
77.Fn getpgid
78system call returns the process group of the specified process;
79otherwise, it returns a value of \-1 and sets
80.Va errno
81to indicate the error.
82.Sh COMPATIBILITY
83This version of
84.Fn getpgrp
85differs from past Berkeley versions by not taking a
86.Fa "pid_t pid"
87argument.
88This incompatibility is required by
89.St -p1003.1-90 .
90.Pp
91From the
92.St -p1003.1-90
93Rationale:
94.Pp
95.Bx 4.3
96provides a
97.Fn getpgrp
98system call that returns the process group ID for a specified process.
99Although this function is used to support job control, all known
100job-control shells always specify the calling process with this
101function.
102Thus, the simpler
103.At V
104.Fn getpgrp
105suffices, and the added complexity of the
106.Bx 4.3
107.Fn getpgrp
108has been omitted from POSIX.1.
109The old functionality is available from the
110.Fn getpgid
111system call.
112.Sh ERRORS
113The
114.Fn getpgid
115system call
116will succeed unless:
117.Bl -tag -width Er
118.It Bq Er ESRCH
119there is no process whose process ID equals
120.Fa pid
121.El
122.Sh SEE ALSO
123.Xr getsid 2 ,
124.Xr setpgid 2 ,
125.Xr termios 4
126.Sh STANDARDS
127The
128.Fn getpgrp
129system call is expected to conform to
130.St -p1003.1-90 .
131.Sh HISTORY
132The
133.Fn getpgrp
134system call appeared in
135.Bx 4.0 .
136The
137.Fn getpgid
138system call is derived from its usage in
139.At V.4 .
140