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*c8b6be0fSAdam Wolk.Dd May 18, 2021 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 4055648840SJohn Baldwin.Fl g Ar pgrp | Fl p Ar pid 4155648840SJohn Baldwin.Sh DESCRIPTION 4255648840SJohn BaldwinThe 4355648840SJohn Baldwin.Nm 4455648840SJohn Baldwincommand is used to mark processes as protected. 4555648840SJohn BaldwinThe kernel does not kill protected processes when swap space is exhausted. 4655648840SJohn BaldwinNote that this protected state is not inherited by child processes by default. 4755648840SJohn Baldwin.Pp 4855648840SJohn BaldwinThe options are: 49828378a6SJoel Dahl.Bl -tag -width XXXXXXXXXX 5055648840SJohn Baldwin.It Fl c 5155648840SJohn BaldwinRemove protection from the specified processes. 5255648840SJohn Baldwin.It Fl d 5355648840SJohn BaldwinApply the operation to all current children of the specified processes. 5455648840SJohn Baldwin.It Fl i 5555648840SJohn BaldwinApply the operation to all future children of the specified processes. 5655648840SJohn Baldwin.It Fl g Ar pgrp 5755648840SJohn BaldwinApply the operation to all processes in the specified process group. 5855648840SJohn Baldwin.It Fl p Ar pid 5955648840SJohn BaldwinApply the operation to the specified process. 6055648840SJohn Baldwin.It Ar command 6155648840SJohn BaldwinExecute 6255648840SJohn Baldwin.Ar command 6355648840SJohn Baldwinas a protected process. 6455648840SJohn Baldwin.El 6555648840SJohn Baldwin.Pp 6655648840SJohn BaldwinNote that only one of the 6755648840SJohn Baldwin.Fl p 6855648840SJohn Baldwinor 6955648840SJohn Baldwin.Fl g 7055648840SJohn Baldwinflags may be specified when adjusting the state of existing processes. 71*c8b6be0fSAdam Wolk.Pp 72*c8b6be0fSAdam WolkDaemons can be protected on startup using 73*c8b6be0fSAdam Wolk.Ao Ar name Ac Ns Va _oomprotect 74*c8b6be0fSAdam Wolkoption from 75*c8b6be0fSAdam Wolk.Xr rc.conf 5 . 7655648840SJohn Baldwin.Sh EXIT STATUS 7755648840SJohn Baldwin.Ex -std 7855648840SJohn Baldwin.Sh EXAMPLES 7955648840SJohn BaldwinMark the Xorg server as protected: 8055648840SJohn Baldwin.Pp 8155648840SJohn Baldwin.Dl "pgrep Xorg | xargs protect -p" 82828378a6SJoel Dahl.Pp 8355648840SJohn BaldwinProtect all ssh sessions and their child processes: 8455648840SJohn Baldwin.Pp 8555648840SJohn Baldwin.Dl "pgrep sshd | xargs protect -dip" 86828378a6SJoel Dahl.Pp 8755648840SJohn BaldwinRemove protection from all current and future processes: 8855648840SJohn Baldwin.Pp 8955648840SJohn Baldwin.Dl "protect -cdi -p 1" 90*c8b6be0fSAdam Wolk.Pp 91*c8b6be0fSAdam WolkUsing 92*c8b6be0fSAdam Wolk.Xr ps 1 93*c8b6be0fSAdam Wolkto check if the protect flag has been applied to the process: 94*c8b6be0fSAdam Wolk.Pp 95*c8b6be0fSAdam Wolk.Dl "ps -O flags,flags2 -p 64430" 96*c8b6be0fSAdam Wolk.Pp 97*c8b6be0fSAdam Wolk.Dl " PID F F2 TT STAT TIME COMMAND" 98*c8b6be0fSAdam Wolk.Dl "64430 10104002 00000001 5 S+ 0:00.00 ./main" 99*c8b6be0fSAdam Wolk.Dl " ^P ^PI" 100*c8b6be0fSAdam Wolk.Pp 101*c8b6be0fSAdam WolkIn the above example 102*c8b6be0fSAdam Wolk.Nm P 103*c8b6be0fSAdam Wolkpoints at the protected flag and 104*c8b6be0fSAdam Wolk.Nm PI 105*c8b6be0fSAdam Wolkpoints at the iheritance flag. 106*c8b6be0fSAdam WolkThe process is protected if 107*c8b6be0fSAdam Wolk.Nm P 108*c8b6be0fSAdam Wolkbit is set to 1. All children of this process will also be protected if 109*c8b6be0fSAdam Wolk.Nm PI 110*c8b6be0fSAdam Wolkbit is set to 1. 11155648840SJohn Baldwin.Sh SEE ALSO 112*c8b6be0fSAdam Wolk.Xr ps 1 , 113*c8b6be0fSAdam Wolk.Xr procctl 2 , 114*c8b6be0fSAdam Wolk.Xr rc.conf 5 11555648840SJohn Baldwin.Sh BUGS 11655648840SJohn BaldwinIf you protect a runaway process that allocates all memory the system will 11755648840SJohn Baldwindeadlock. 118