1.\" Copyright (c) 2013 Hudson River Trading LLC 2.\" Written by: John H. Baldwin <jhb@FreeBSD.org> 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd July 12, 2022 29.Dt PROTECT 1 30.Os 31.Sh NAME 32.Nm protect 33.Nd "protect processes from being killed when swap space is exhausted" 34.Sh SYNOPSIS 35.Nm 36.Op Fl i 37.Ar command 38.Nm 39.Op Fl cdi 40.Fl g Ar pgrp 41.Nm 42.Op Fl cdi 43.Fl p Ar pid 44.Sh DESCRIPTION 45The 46.Nm 47command is used to mark processes as protected. 48The kernel does not kill protected processes when swap space is exhausted. 49Note that this protected state is not inherited by child processes by default. 50.Pp 51The options are: 52.Bl -tag -width command 53.It Fl c 54Remove protection from the specified processes. 55.It Fl d 56Apply the operation to all current children of the specified processes. 57.It Fl i 58Apply the operation to all future children of the specified processes. 59.It Fl g Ar pgrp 60Apply the operation to all processes in the specified process group. 61.It Fl p Ar pid 62Apply the operation to the specified process. 63.It Ar command 64Execute 65.Ar command 66as a protected process. 67.El 68.Pp 69Note that only one of the 70.Fl p 71or 72.Fl g 73flags may be specified when adjusting the state of existing processes. 74.Pp 75Daemons can be protected on startup using 76.Ao Ar name Ac Ns Va _oomprotect 77option from 78.Xr rc.conf 5 . 79.Sh EXIT STATUS 80.Ex -std 81.Sh EXAMPLES 82Mark the Xorg server as protected: 83.Pp 84.Dl "pgrep Xorg | xargs protect -p" 85.Pp 86Protect all ssh sessions and their child processes: 87.Pp 88.Dl "pgrep sshd | xargs protect -dip" 89.Pp 90Remove protection from all current and future processes: 91.Pp 92.Dl "protect -cdi -p 1" 93.Pp 94Using 95.Xr ps 1 96to check if the protect flag has been applied to the process: 97.Pp 98.Dl "ps -O flags,flags2 -p 64430" 99.Pp 100.Dl " PID F F2 TT STAT TIME COMMAND" 101.Dl "64430 10104002 00000001 5 S+ 0:00.00 ./main" 102.Dl " ^P ^PI" 103.Pp 104In the above example 105.Nm P 106points at the protected flag and 107.Nm PI 108points at the inheritance flag. 109The process is protected if 110.Nm P 111bit is set to 1. 112All children of this process will also be protected if 113.Nm PI 114bit is set to 1. 115.Sh DIAGNOSTICS 116.Bl -diag 117.It "protect: procctl: Operation not permitted" 118The 119.Nm 120command does not have the required permissions to protect selected processes. 121There are many reasons why this could be the case, e.g.: 122.Bl -dash 123.It 124.Nm 125is not executed by root. 126.It 127.Nm 128is executed inside a 129.Xr jail 8 , 130which is not supported at the moment. 131.El 132.El 133.Sh SEE ALSO 134.Xr ps 1 , 135.Xr procctl 2 , 136.Xr rc.conf 5 137.Sh BUGS 138If you protect a runaway process that allocates all memory the system will 139deadlock. 140