2013-09-19 18:53:42 +00:00
|
|
|
.\" Copyright (c) 2013 Advanced Computing Technologies LLC
|
|
|
|
.\" Written by: John H. Baldwin <jhb@FreeBSD.org>
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
2014-12-15 12:01:42 +00:00
|
|
|
.\" Copyright (c) 2014 The FreeBSD Foundation
|
|
|
|
.\" Portions of this documentation were written by Konstantin Belousov
|
|
|
|
.\" under sponsorship from the FreeBSD Foundation.
|
|
|
|
.\"
|
2013-09-19 18:53:42 +00:00
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2014-12-17 01:36:00 +00:00
|
|
|
.Dd December 16, 2014
|
2013-09-19 18:53:42 +00:00
|
|
|
.Dt PROCCTL 2
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm procctl
|
|
|
|
.Nd control processes
|
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In sys/procctl.h
|
|
|
|
.Ft int
|
|
|
|
.Fn procctl "idtype_t idtype" "id_t id" "int cmd" "void *arg"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn procctl
|
|
|
|
system call provides for control over processes.
|
|
|
|
The
|
|
|
|
.Fa idtype
|
|
|
|
and
|
|
|
|
.Fa id
|
|
|
|
arguments specify the set of processes to control.
|
|
|
|
If multiple processes match the identifier,
|
|
|
|
.Nm
|
|
|
|
will make a
|
|
|
|
.Dq best effort
|
2014-07-09 01:33:35 +00:00
|
|
|
to control as many of the selected processes as possible.
|
2013-09-19 18:53:42 +00:00
|
|
|
An error is only returned if no selected processes successfully complete
|
|
|
|
the request.
|
|
|
|
The following identifier types are supported:
|
2013-09-19 19:43:38 +00:00
|
|
|
.Bl -tag -width "Dv P_PGID"
|
2013-09-19 18:53:42 +00:00
|
|
|
.It Dv P_PID
|
|
|
|
Control the process with the process ID
|
|
|
|
.Fa id .
|
|
|
|
.It Dv P_PGID
|
|
|
|
Control processes belonging to the process group with the ID
|
|
|
|
.Fa id .
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The control request to perform is specified by the
|
|
|
|
.Fa cmd
|
|
|
|
argument.
|
|
|
|
The following commands are supported:
|
2014-12-15 12:01:42 +00:00
|
|
|
.Bl -tag -width "Dv PROC_REAP_GETPIDS"
|
2013-09-19 18:53:42 +00:00
|
|
|
.It Dv PROC_SPROTECT
|
|
|
|
Set process protection state.
|
|
|
|
This is used to mark a process as protected from being killed if the system
|
|
|
|
exhausts available memory and swap.
|
|
|
|
The
|
|
|
|
.Fa arg
|
|
|
|
parameter must point to an integer containing an operation and zero or more
|
|
|
|
optional flags.
|
|
|
|
The following operations are supported:
|
2013-09-19 19:43:38 +00:00
|
|
|
.Bl -tag -width "Dv PPROT_CLEAR"
|
2013-09-19 18:53:42 +00:00
|
|
|
.It Dv PPROT_SET
|
|
|
|
Mark the selected processes as protected.
|
|
|
|
.It Dv PPROT_CLEAR
|
|
|
|
Clear the protected state of selected processes.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The following optional flags are supported:
|
2013-09-19 19:43:38 +00:00
|
|
|
.Bl -tag -width "Dv PPROT_DESCE"
|
2013-09-19 18:53:42 +00:00
|
|
|
.It Dv PPROT_DESCEND
|
|
|
|
Apply the requested operation to all child processes of each selected process
|
|
|
|
in addition to each selected process.
|
|
|
|
.It Dv PPROT_INHERIT
|
|
|
|
When used with
|
|
|
|
.Dv PPROT_SET ,
|
|
|
|
mark all future child processes of each selected process as protected.
|
|
|
|
Future child processes will also mark all of their future child processes.
|
|
|
|
.El
|
2014-12-15 12:01:42 +00:00
|
|
|
.It Dv PROC_REAP_ACQUIRE
|
|
|
|
Acquires the reaper status for the current process.
|
2014-12-17 01:32:27 +00:00
|
|
|
The status means that children orphaned by the reaper's descendants
|
|
|
|
that were forked after the acquisition of the status are reparented to the
|
2014-12-15 12:01:42 +00:00
|
|
|
reaper.
|
|
|
|
After the system initialization,
|
|
|
|
.Xr init 8
|
|
|
|
is the default reaper.
|
|
|
|
.Pp
|
|
|
|
.It Dv PROC_REAP_RELEASE
|
2014-12-17 01:32:27 +00:00
|
|
|
Releases the reaper state for the current process.
|
2014-12-15 12:01:42 +00:00
|
|
|
The reaper of the current process becomes the new reaper of the
|
2014-12-17 01:32:27 +00:00
|
|
|
current process's descendants.
|
2014-12-15 12:01:42 +00:00
|
|
|
.It Dv PROC_REAP_STATUS
|
|
|
|
Provides the information about the reaper of the specified process,
|
2014-12-17 01:32:27 +00:00
|
|
|
or the process itself when it is a reaper.
|
2014-12-15 12:01:42 +00:00
|
|
|
The
|
|
|
|
.Fa data
|
2014-12-17 01:32:27 +00:00
|
|
|
argument must point to a
|
|
|
|
.Vt procctl_reaper_status
|
|
|
|
structure which is filled in by the syscall on successful return.
|
2014-12-15 12:01:42 +00:00
|
|
|
.Bd -literal
|
|
|
|
struct procctl_reaper_status {
|
|
|
|
u_int rs_flags;
|
|
|
|
u_int rs_children;
|
|
|
|
u_int rs_descendants;
|
|
|
|
pid_t rs_reaper;
|
|
|
|
pid_t rs_pid;
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
The
|
|
|
|
.Fa rs_flags
|
|
|
|
may have the following flags returned:
|
|
|
|
.Bl -tag -width "Dv REAPER_STATUS_REALINIT"
|
|
|
|
.It Dv REAPER_STATUS_OWNED
|
2014-12-17 01:32:27 +00:00
|
|
|
The specified process has acquired the reaper status and has not
|
2014-12-15 12:01:42 +00:00
|
|
|
released it.
|
2014-12-17 01:32:27 +00:00
|
|
|
When the flag is returned, the specified process
|
|
|
|
.Fa id ,
|
|
|
|
pid, identifies the reaper, otherwise the
|
2014-12-15 12:01:42 +00:00
|
|
|
.Fa rs_reaper
|
2014-12-17 01:32:27 +00:00
|
|
|
field of the structure is set to the pid of the reaper
|
|
|
|
for the specified process id.
|
2014-12-15 12:01:42 +00:00
|
|
|
.It Dv REAPER_STATUS_REALINIT
|
|
|
|
The specified process is the root of the reaper tree, i.e.
|
2014-12-17 01:32:27 +00:00
|
|
|
.Xr init 8 .
|
2014-12-15 12:01:42 +00:00
|
|
|
.El
|
|
|
|
The
|
|
|
|
.Fa rs_children
|
2014-12-17 01:32:27 +00:00
|
|
|
field returns the number of children of the reaper.
|
2014-12-15 12:01:42 +00:00
|
|
|
The
|
|
|
|
.Fa rs_descendants
|
2014-12-17 01:32:27 +00:00
|
|
|
field returns the total number of descendants of the reaper(s),
|
|
|
|
not counting descendants of the reaper in the subtree.
|
2014-12-15 12:01:42 +00:00
|
|
|
The
|
|
|
|
.Fa rs_reaper
|
2014-12-17 01:32:27 +00:00
|
|
|
field returns the reaper pid.
|
2014-12-15 12:01:42 +00:00
|
|
|
The
|
|
|
|
.Fa rs_pid
|
2014-12-17 01:32:27 +00:00
|
|
|
returns the pid of one reaper child if there are any descendants.
|
2014-12-15 12:01:42 +00:00
|
|
|
.It Dv PROC_REAP_GETPIDS
|
|
|
|
Queries the list of descendants of the reaper of the specified process.
|
2014-12-17 01:32:27 +00:00
|
|
|
The request takes a pointer to a
|
|
|
|
.Vt procctl_reaper_pids
|
|
|
|
structure in the
|
|
|
|
.Fa data
|
|
|
|
parameter.
|
2014-12-15 12:01:42 +00:00
|
|
|
.Bd -literal
|
|
|
|
struct procctl_reaper_pids {
|
|
|
|
u_int rp_count;
|
|
|
|
struct procctl_reaper_pidinfo *rp_pids;
|
|
|
|
};
|
|
|
|
.Ed
|
2014-12-17 01:32:27 +00:00
|
|
|
When called, the
|
2014-12-15 12:01:42 +00:00
|
|
|
.Fa rp_pids
|
2014-12-17 01:32:27 +00:00
|
|
|
field must point to an array of
|
2014-12-15 12:01:42 +00:00
|
|
|
.Vt procctl_reaper_pidinfo
|
2014-12-17 01:32:27 +00:00
|
|
|
structures, to be filled in on return,
|
2014-12-15 12:01:42 +00:00
|
|
|
and the
|
|
|
|
.Fa rp_count
|
2014-12-17 01:32:27 +00:00
|
|
|
field must specify the size of the array,
|
|
|
|
into which no more than
|
|
|
|
.Fa rp_count
|
|
|
|
elements will be filled in by the kernel.
|
2014-12-15 12:01:42 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Vt "struct procctl_reaper_pidinfo"
|
2014-12-17 01:32:27 +00:00
|
|
|
structure provides some information about one of the reaper's descendants.
|
|
|
|
Note that for a descendant that is not a child, it may be incorrectly
|
|
|
|
identified because of a race in which the original child process exited
|
|
|
|
and the exited process's pid was reused for an unrelated process.
|
2014-12-15 12:01:42 +00:00
|
|
|
.Bd -literal
|
|
|
|
struct procctl_reaper_pidinfo {
|
|
|
|
pid_t pi_pid;
|
|
|
|
pid_t pi_subtree;
|
|
|
|
u_int pi_flags;
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
The
|
|
|
|
.Fa pi_pid
|
2014-12-17 01:32:27 +00:00
|
|
|
field is the process id of the descendant.
|
2014-12-15 12:01:42 +00:00
|
|
|
The
|
|
|
|
.Fa pi_subtree
|
2014-12-17 01:32:27 +00:00
|
|
|
field provides the pid of the child of the reaper, which is the (grand-)parent
|
2014-12-15 12:01:42 +00:00
|
|
|
of the process.
|
|
|
|
The
|
|
|
|
.Fa pi_flags
|
2014-12-17 01:32:27 +00:00
|
|
|
field returns the following flags, further describing the descendant:
|
2014-12-15 12:01:42 +00:00
|
|
|
.Bl -tag -width "Dv REAPER_PIDINFO_VALID"
|
|
|
|
.It Dv REAPER_PIDINFO_VALID
|
2014-12-17 01:32:27 +00:00
|
|
|
Set to indicate that the
|
2014-12-15 12:01:42 +00:00
|
|
|
.Vt procctl_reaper_pidinfo
|
2014-12-17 01:32:27 +00:00
|
|
|
structure was filled in by the kernel.
|
2014-12-15 12:01:42 +00:00
|
|
|
Zero-filling the
|
|
|
|
.Fa rp_pids
|
2014-12-17 01:32:27 +00:00
|
|
|
array and testing the
|
|
|
|
.Dv REAPER_PIDINFO_VALID
|
|
|
|
flag allows the caller to detect the end
|
|
|
|
of the returned array.
|
2014-12-15 12:01:42 +00:00
|
|
|
.It Dv REAPER_PIDINFO_CHILD
|
|
|
|
The
|
|
|
|
.Fa pi_pid
|
2014-12-17 01:32:27 +00:00
|
|
|
field identifies the direct child of the reaper.
|
2014-12-15 12:01:42 +00:00
|
|
|
.El
|
|
|
|
.It Dv PROC_REAP_KILL
|
2014-12-17 01:32:27 +00:00
|
|
|
Request to deliver a signal to some subset of the descendants of the reaper.
|
2014-12-15 12:01:42 +00:00
|
|
|
The
|
|
|
|
.Fa data
|
2014-12-17 01:32:27 +00:00
|
|
|
parameter must point to a
|
2014-12-15 12:01:42 +00:00
|
|
|
.Vt procctl_reaper_kill
|
|
|
|
structure, which is used both for parameters and status return.
|
|
|
|
.Bd -literal
|
|
|
|
struct procctl_reaper_kill {
|
|
|
|
int rk_sig;
|
|
|
|
u_int rk_flags;
|
|
|
|
pid_t rk_subtree;
|
|
|
|
u_int rk_killed;
|
|
|
|
pid_t rk_fpid;
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
The
|
|
|
|
.Fa rk_sig
|
2014-12-17 01:32:27 +00:00
|
|
|
field specifies the signal to be delivered.
|
2014-12-15 12:01:42 +00:00
|
|
|
Zero is not a valid signal number, unlike
|
|
|
|
.Xr kill 2 .
|
|
|
|
The
|
|
|
|
.Fa rk_flags
|
2014-12-17 01:32:27 +00:00
|
|
|
field further directs the operation.
|
2014-12-15 12:01:42 +00:00
|
|
|
It is or-ed from the following flags:
|
|
|
|
.Bl -tag -width "Dv REAPER_KILL_CHILDREN"
|
|
|
|
.It Dv REAPER_KILL_CHILDREN
|
|
|
|
Deliver the specified signal only to direct children of the reaper.
|
|
|
|
.It Dv REAPER_KILL_SUBTREE
|
2014-12-17 01:32:27 +00:00
|
|
|
Deliver the specified signal only to descendants that were forked by
|
|
|
|
the direct child with pid specified in the
|
|
|
|
.Fa rk_subtree
|
|
|
|
field.
|
2014-12-15 12:01:42 +00:00
|
|
|
.El
|
2014-12-17 01:32:27 +00:00
|
|
|
If neither the
|
2014-12-15 12:01:42 +00:00
|
|
|
.Dv REAPER_KILL_CHILDREN
|
2014-12-17 01:32:27 +00:00
|
|
|
nor the
|
2014-12-15 12:01:42 +00:00
|
|
|
.Dv REAPER_KILL_SUBTREE
|
|
|
|
flags are specified, all current descendants of the reaper are signalled.
|
|
|
|
.Pp
|
2014-12-17 01:32:27 +00:00
|
|
|
If a signal was delivered to any process, the return value from the request
|
2014-12-15 12:01:42 +00:00
|
|
|
is zero.
|
2014-12-17 01:32:27 +00:00
|
|
|
In this case, the
|
2014-12-15 12:01:42 +00:00
|
|
|
.Fa rk_killed
|
2014-12-17 01:32:27 +00:00
|
|
|
field identifies the number of processes signalled.
|
2014-12-15 12:01:42 +00:00
|
|
|
The
|
|
|
|
.Fa rk_fpid
|
|
|
|
field is set to the pid of the first process for which signal
|
|
|
|
delivery failed, e.g. due to the permission problems.
|
|
|
|
If no such process exist, the
|
|
|
|
.Fa rk_fpid
|
2014-12-17 01:32:27 +00:00
|
|
|
field is set to -1.
|
2013-09-19 18:53:42 +00:00
|
|
|
.El
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
If an error occurs, a value of -1 is returned and
|
|
|
|
.Va errno
|
|
|
|
is set to indicate the error.
|
|
|
|
.Sh ERRORS
|
|
|
|
The
|
|
|
|
.Fn procctl
|
|
|
|
system call
|
|
|
|
will fail if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EFAULT
|
|
|
|
The
|
|
|
|
.Fa arg
|
2014-12-17 01:32:27 +00:00
|
|
|
parameter points outside the process's allocated address space.
|
2013-09-19 18:53:42 +00:00
|
|
|
.It Bq Er EINVAL
|
|
|
|
The
|
|
|
|
.Fa cmd
|
|
|
|
argument specifies an unsupported command.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa idtype
|
|
|
|
argument specifies an unsupported identifier type.
|
|
|
|
.It Bq Er EPERM
|
|
|
|
The calling process does not have permission to perform the requested
|
|
|
|
operation on any of the selected processes.
|
|
|
|
.It Bq Er ESRCH
|
|
|
|
No processes matched the requested
|
|
|
|
.Fa idtype
|
|
|
|
and
|
|
|
|
.Fa id .
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
An invalid operation or flag was passed in
|
|
|
|
.Fa arg
|
|
|
|
for a
|
|
|
|
.Dv PROC_SPROTECT
|
|
|
|
command.
|
2014-12-15 12:01:42 +00:00
|
|
|
.It Bq Er EPERM
|
|
|
|
The
|
|
|
|
.Fa idtype
|
|
|
|
argument is not equal to
|
|
|
|
.Dv P_PID ,
|
|
|
|
or
|
|
|
|
.Fa id
|
|
|
|
is not equal to the pid of the calling process, for
|
|
|
|
.Dv PROC_REAP_ACQUIRE
|
|
|
|
or
|
|
|
|
.Dv PROC_REAP_RELEASE
|
|
|
|
requests.
|
|
|
|
.It Bq Er EINVAL
|
2014-12-17 01:32:27 +00:00
|
|
|
Invalid or undefined flags were passed to a
|
2014-12-15 12:01:42 +00:00
|
|
|
.Dv PROC_REAP_KILL
|
|
|
|
request.
|
|
|
|
.It Bq Er EINVAL
|
2014-12-17 01:32:27 +00:00
|
|
|
An invalid or zero signal number was requested for a
|
2014-12-15 12:01:42 +00:00
|
|
|
.Dv PROC_REAP_KILL
|
|
|
|
request.
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
The
|
|
|
|
.Dv PROC_REAP_RELEASE
|
|
|
|
request was issued by the
|
|
|
|
.Xr init 8
|
|
|
|
process.
|
|
|
|
.It Bq Er EBUSY
|
|
|
|
The
|
|
|
|
.Dv PROC_REAP_ACQUIRE
|
2014-12-17 01:32:27 +00:00
|
|
|
request was issued by a process that had already acquired reaper status
|
|
|
|
and has not yet released it.
|
2013-09-19 18:53:42 +00:00
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
2014-12-15 12:01:42 +00:00
|
|
|
.Xr kill 2 ,
|
|
|
|
.Xr ptrace 2 ,
|
|
|
|
.Xr wait 2 ,
|
|
|
|
.Xr init 8
|
2013-09-19 18:53:42 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Fn procctl
|
|
|
|
function appeared in
|
2014-01-28 21:40:10 +00:00
|
|
|
.Fx 10.0 .
|
2014-12-17 01:32:27 +00:00
|
|
|
The reaper facility is based on a similar feature of Linux and
|
2014-12-15 12:01:42 +00:00
|
|
|
DragonflyBSD, and first appeared in
|
|
|
|
.Fx 10.2 .
|