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.\" 26*6452fb1eSMateusz Piotrowski.Dd July 12, 2022 2755648840SJohn Baldwin.Dt PROTECT 1 2855648840SJohn Baldwin.Os 2955648840SJohn Baldwin.Sh NAME 3055648840SJohn Baldwin.Nm protect 3155648840SJohn Baldwin.Nd "protect processes from being killed when swap space is exhausted" 3255648840SJohn Baldwin.Sh SYNOPSIS 3355648840SJohn Baldwin.Nm 3455648840SJohn Baldwin.Op Fl i 3555648840SJohn Baldwin.Ar command 3655648840SJohn Baldwin.Nm 3755648840SJohn Baldwin.Op Fl cdi 38cb56f860SMateusz Piotrowski.Fl g Ar pgrp 39cb56f860SMateusz Piotrowski.Nm 40cb56f860SMateusz Piotrowski.Op Fl cdi 41cb56f860SMateusz Piotrowski.Fl p Ar pid 4255648840SJohn Baldwin.Sh DESCRIPTION 4355648840SJohn BaldwinThe 4455648840SJohn Baldwin.Nm 4555648840SJohn Baldwincommand is used to mark processes as protected. 4655648840SJohn BaldwinThe kernel does not kill protected processes when swap space is exhausted. 4755648840SJohn BaldwinNote that this protected state is not inherited by child processes by default. 4855648840SJohn Baldwin.Pp 4955648840SJohn BaldwinThe options are: 50cb56f860SMateusz Piotrowski.Bl -tag -width command 5155648840SJohn Baldwin.It Fl c 5255648840SJohn BaldwinRemove protection from the specified processes. 5355648840SJohn Baldwin.It Fl d 5455648840SJohn BaldwinApply the operation to all current children of the specified processes. 5555648840SJohn Baldwin.It Fl i 5655648840SJohn BaldwinApply the operation to all future children of the specified processes. 5755648840SJohn Baldwin.It Fl g Ar pgrp 5855648840SJohn BaldwinApply the operation to all processes in the specified process group. 5955648840SJohn Baldwin.It Fl p Ar pid 6055648840SJohn BaldwinApply the operation to the specified process. 6155648840SJohn Baldwin.It Ar command 6255648840SJohn BaldwinExecute 6355648840SJohn Baldwin.Ar command 6455648840SJohn Baldwinas a protected process. 6555648840SJohn Baldwin.El 6655648840SJohn Baldwin.Pp 6755648840SJohn BaldwinNote that only one of the 6855648840SJohn Baldwin.Fl p 6955648840SJohn Baldwinor 7055648840SJohn Baldwin.Fl g 7155648840SJohn Baldwinflags may be specified when adjusting the state of existing processes. 72c8b6be0fSAdam Wolk.Pp 73c8b6be0fSAdam WolkDaemons can be protected on startup using 74c8b6be0fSAdam Wolk.Ao Ar name Ac Ns Va _oomprotect 75c8b6be0fSAdam Wolkoption from 76c8b6be0fSAdam Wolk.Xr rc.conf 5 . 7755648840SJohn Baldwin.Sh EXIT STATUS 7855648840SJohn Baldwin.Ex -std 7955648840SJohn Baldwin.Sh EXAMPLES 8055648840SJohn BaldwinMark the Xorg server as protected: 8155648840SJohn Baldwin.Pp 8255648840SJohn Baldwin.Dl "pgrep Xorg | xargs protect -p" 83828378a6SJoel Dahl.Pp 8455648840SJohn BaldwinProtect all ssh sessions and their child processes: 8555648840SJohn Baldwin.Pp 8655648840SJohn Baldwin.Dl "pgrep sshd | xargs protect -dip" 87828378a6SJoel Dahl.Pp 8855648840SJohn BaldwinRemove protection from all current and future processes: 8955648840SJohn Baldwin.Pp 9055648840SJohn Baldwin.Dl "protect -cdi -p 1" 91c8b6be0fSAdam Wolk.Pp 92c8b6be0fSAdam WolkUsing 93c8b6be0fSAdam Wolk.Xr ps 1 94c8b6be0fSAdam Wolkto check if the protect flag has been applied to the process: 95c8b6be0fSAdam Wolk.Pp 96c8b6be0fSAdam Wolk.Dl "ps -O flags,flags2 -p 64430" 97c8b6be0fSAdam Wolk.Pp 98c8b6be0fSAdam Wolk.Dl " PID F F2 TT STAT TIME COMMAND" 99c8b6be0fSAdam Wolk.Dl "64430 10104002 00000001 5 S+ 0:00.00 ./main" 100c8b6be0fSAdam Wolk.Dl " ^P ^PI" 101c8b6be0fSAdam Wolk.Pp 102c8b6be0fSAdam WolkIn the above example 103c8b6be0fSAdam Wolk.Nm P 104c8b6be0fSAdam Wolkpoints at the protected flag and 105c8b6be0fSAdam Wolk.Nm PI 106bd1eafcdSDaniel Ebdrup Jensenpoints at the inheritance flag. 107c8b6be0fSAdam WolkThe process is protected if 108c8b6be0fSAdam Wolk.Nm P 109bd1eafcdSDaniel Ebdrup Jensenbit is set to 1. 110bd1eafcdSDaniel Ebdrup JensenAll children of this process will also be protected if 111c8b6be0fSAdam Wolk.Nm PI 112c8b6be0fSAdam Wolkbit is set to 1. 113*6452fb1eSMateusz Piotrowski.Sh DIAGNOSTICS 114*6452fb1eSMateusz Piotrowski.Bl -diag 115*6452fb1eSMateusz Piotrowski.It "protect: procctl: Operation not permitted" 116*6452fb1eSMateusz PiotrowskiThe 117*6452fb1eSMateusz Piotrowski.Nm 118*6452fb1eSMateusz Piotrowskicommand does not have the required permissions to protect selected processes. 119*6452fb1eSMateusz PiotrowskiThere are many reasons why this could be the case, e.g.: 120*6452fb1eSMateusz Piotrowski.Bl -dash 121*6452fb1eSMateusz Piotrowski.It 122*6452fb1eSMateusz Piotrowski.Nm 123*6452fb1eSMateusz Piotrowskiis not executed by root. 124*6452fb1eSMateusz Piotrowski.It 125*6452fb1eSMateusz Piotrowski.Nm 126*6452fb1eSMateusz Piotrowskiis executed inside a 127*6452fb1eSMateusz Piotrowski.Xr jail 8 , 128*6452fb1eSMateusz Piotrowskiwhich is not supported at the moment. 129*6452fb1eSMateusz Piotrowski.El 130*6452fb1eSMateusz Piotrowski.El 13155648840SJohn Baldwin.Sh SEE ALSO 132c8b6be0fSAdam Wolk.Xr ps 1 , 133c8b6be0fSAdam Wolk.Xr procctl 2 , 134c8b6be0fSAdam Wolk.Xr rc.conf 5 13555648840SJohn Baldwin.Sh BUGS 13655648840SJohn BaldwinIf you protect a runaway process that allocates all memory the system will 13755648840SJohn Baldwindeadlock. 138