xref: /freebsd/usr.bin/protect/protect.1 (revision 6452fb1e87ed9d00b52fa1e63e7c3a7516c9586c)
1179fa75eSJohn Baldwin.\" Copyright (c) 2013 Hudson River Trading LLC
255648840SJohn Baldwin.\" Written by: John H. Baldwin <jhb@FreeBSD.org>
355648840SJohn Baldwin.\" All rights reserved.
455648840SJohn Baldwin.\"
555648840SJohn Baldwin.\" Redistribution and use in source and binary forms, with or without
655648840SJohn Baldwin.\" modification, are permitted provided that the following conditions
755648840SJohn Baldwin.\" are met:
855648840SJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright
955648840SJohn Baldwin.\"    notice, this list of conditions and the following disclaimer.
1055648840SJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright
1155648840SJohn Baldwin.\"    notice, this list of conditions and the following disclaimer in the
1255648840SJohn Baldwin.\"    documentation and/or other materials provided with the distribution.
1355648840SJohn Baldwin.\"
1455648840SJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1555648840SJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1655648840SJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1755648840SJohn Baldwin.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1855648840SJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1955648840SJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2055648840SJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2155648840SJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2255648840SJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2355648840SJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2455648840SJohn Baldwin.\" SUCH DAMAGE.
2555648840SJohn Baldwin.\"
2655648840SJohn Baldwin.\" $FreeBSD$
2755648840SJohn Baldwin.\"
28*6452fb1eSMateusz Piotrowski.Dd July 12, 2022
2955648840SJohn Baldwin.Dt PROTECT 1
3055648840SJohn Baldwin.Os
3155648840SJohn Baldwin.Sh NAME
3255648840SJohn Baldwin.Nm protect
3355648840SJohn Baldwin.Nd "protect processes from being killed when swap space is exhausted"
3455648840SJohn Baldwin.Sh SYNOPSIS
3555648840SJohn Baldwin.Nm
3655648840SJohn Baldwin.Op Fl i
3755648840SJohn Baldwin.Ar command
3855648840SJohn Baldwin.Nm
3955648840SJohn Baldwin.Op Fl cdi
40cb56f860SMateusz Piotrowski.Fl g Ar pgrp
41cb56f860SMateusz Piotrowski.Nm
42cb56f860SMateusz Piotrowski.Op Fl cdi
43cb56f860SMateusz Piotrowski.Fl p Ar pid
4455648840SJohn Baldwin.Sh DESCRIPTION
4555648840SJohn BaldwinThe
4655648840SJohn Baldwin.Nm
4755648840SJohn Baldwincommand is used to mark processes as protected.
4855648840SJohn BaldwinThe kernel does not kill protected processes when swap space is exhausted.
4955648840SJohn BaldwinNote that this protected state is not inherited by child processes by default.
5055648840SJohn Baldwin.Pp
5155648840SJohn BaldwinThe options are:
52cb56f860SMateusz Piotrowski.Bl -tag -width command
5355648840SJohn Baldwin.It Fl c
5455648840SJohn BaldwinRemove protection from the specified processes.
5555648840SJohn Baldwin.It Fl d
5655648840SJohn BaldwinApply the operation to all current children of the specified processes.
5755648840SJohn Baldwin.It Fl i
5855648840SJohn BaldwinApply the operation to all future children of the specified processes.
5955648840SJohn Baldwin.It Fl g Ar pgrp
6055648840SJohn BaldwinApply the operation to all processes in the specified process group.
6155648840SJohn Baldwin.It Fl p Ar pid
6255648840SJohn BaldwinApply the operation to the specified process.
6355648840SJohn Baldwin.It Ar command
6455648840SJohn BaldwinExecute
6555648840SJohn Baldwin.Ar command
6655648840SJohn Baldwinas a protected process.
6755648840SJohn Baldwin.El
6855648840SJohn Baldwin.Pp
6955648840SJohn BaldwinNote that only one of the
7055648840SJohn Baldwin.Fl p
7155648840SJohn Baldwinor
7255648840SJohn Baldwin.Fl g
7355648840SJohn Baldwinflags may be specified when adjusting the state of existing processes.
74c8b6be0fSAdam Wolk.Pp
75c8b6be0fSAdam WolkDaemons can be protected on startup using
76c8b6be0fSAdam Wolk.Ao Ar name Ac Ns Va _oomprotect
77c8b6be0fSAdam Wolkoption from
78c8b6be0fSAdam Wolk.Xr rc.conf 5 .
7955648840SJohn Baldwin.Sh EXIT STATUS
8055648840SJohn Baldwin.Ex -std
8155648840SJohn Baldwin.Sh EXAMPLES
8255648840SJohn BaldwinMark the Xorg server as protected:
8355648840SJohn Baldwin.Pp
8455648840SJohn Baldwin.Dl "pgrep Xorg | xargs protect -p"
85828378a6SJoel Dahl.Pp
8655648840SJohn BaldwinProtect all ssh sessions and their child processes:
8755648840SJohn Baldwin.Pp
8855648840SJohn Baldwin.Dl "pgrep sshd | xargs protect -dip"
89828378a6SJoel Dahl.Pp
9055648840SJohn BaldwinRemove protection from all current and future processes:
9155648840SJohn Baldwin.Pp
9255648840SJohn Baldwin.Dl "protect -cdi -p 1"
93c8b6be0fSAdam Wolk.Pp
94c8b6be0fSAdam WolkUsing
95c8b6be0fSAdam Wolk.Xr ps 1
96c8b6be0fSAdam Wolkto check if the protect flag has been applied to the process:
97c8b6be0fSAdam Wolk.Pp
98c8b6be0fSAdam Wolk.Dl "ps -O flags,flags2 -p 64430"
99c8b6be0fSAdam Wolk.Pp
100c8b6be0fSAdam Wolk.Dl " PID        F       F2 TT  STAT    TIME COMMAND"
101c8b6be0fSAdam Wolk.Dl "64430 10104002 00000001  5  S+   0:00.00 ./main"
102c8b6be0fSAdam Wolk.Dl "        ^P            ^PI"
103c8b6be0fSAdam Wolk.Pp
104c8b6be0fSAdam WolkIn the above example
105c8b6be0fSAdam Wolk.Nm P
106c8b6be0fSAdam Wolkpoints at the protected flag and
107c8b6be0fSAdam Wolk.Nm PI
108bd1eafcdSDaniel Ebdrup Jensenpoints at the inheritance flag.
109c8b6be0fSAdam WolkThe process is protected if
110c8b6be0fSAdam Wolk.Nm P
111bd1eafcdSDaniel Ebdrup Jensenbit is set to 1.
112bd1eafcdSDaniel Ebdrup JensenAll children of this process will also be protected if
113c8b6be0fSAdam Wolk.Nm PI
114c8b6be0fSAdam Wolkbit is set to 1.
115*6452fb1eSMateusz Piotrowski.Sh DIAGNOSTICS
116*6452fb1eSMateusz Piotrowski.Bl -diag
117*6452fb1eSMateusz Piotrowski.It "protect: procctl: Operation not permitted"
118*6452fb1eSMateusz PiotrowskiThe
119*6452fb1eSMateusz Piotrowski.Nm
120*6452fb1eSMateusz Piotrowskicommand does not have the required permissions to protect selected processes.
121*6452fb1eSMateusz PiotrowskiThere are many reasons why this could be the case, e.g.:
122*6452fb1eSMateusz Piotrowski.Bl -dash
123*6452fb1eSMateusz Piotrowski.It
124*6452fb1eSMateusz Piotrowski.Nm
125*6452fb1eSMateusz Piotrowskiis not executed by root.
126*6452fb1eSMateusz Piotrowski.It
127*6452fb1eSMateusz Piotrowski.Nm
128*6452fb1eSMateusz Piotrowskiis executed inside a
129*6452fb1eSMateusz Piotrowski.Xr jail 8 ,
130*6452fb1eSMateusz Piotrowskiwhich is not supported at the moment.
131*6452fb1eSMateusz Piotrowski.El
132*6452fb1eSMateusz Piotrowski.El
13355648840SJohn Baldwin.Sh SEE ALSO
134c8b6be0fSAdam Wolk.Xr ps 1 ,
135c8b6be0fSAdam Wolk.Xr procctl 2 ,
136c8b6be0fSAdam Wolk.Xr rc.conf 5
13755648840SJohn Baldwin.Sh BUGS
13855648840SJohn BaldwinIf you protect a runaway process that allocates all memory the system will
13955648840SJohn Baldwindeadlock.
140