xref: /freebsd/usr.bin/protect/protect.1 (revision 3e8eb5c7f4909209c042403ddee340b2ee7003a5)
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 April 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 | Fl p Ar pid
41.Sh DESCRIPTION
42The
43.Nm
44command is used to mark processes as protected.
45The kernel does not kill protected processes when swap space is exhausted.
46Note that this protected state is not inherited by child processes by default.
47.Pp
48The options are:
49.Bl -tag -width XXXXXXXXXX
50.It Fl c
51Remove protection from the specified processes.
52.It Fl d
53Apply the operation to all current children of the specified processes.
54.It Fl i
55Apply the operation to all future children of the specified processes.
56.It Fl g Ar pgrp
57Apply the operation to all processes in the specified process group.
58.It Fl p Ar pid
59Apply the operation to the specified process.
60.It Ar command
61Execute
62.Ar command
63as a protected process.
64.El
65.Pp
66Note that only one of the
67.Fl p
68or
69.Fl g
70flags may be specified when adjusting the state of existing processes.
71.Pp
72Daemons can be protected on startup using
73.Ao Ar name Ac Ns Va _oomprotect
74option from
75.Xr rc.conf 5 .
76.Sh EXIT STATUS
77.Ex -std
78.Sh EXAMPLES
79Mark the Xorg server as protected:
80.Pp
81.Dl "pgrep Xorg | xargs protect -p"
82.Pp
83Protect all ssh sessions and their child processes:
84.Pp
85.Dl "pgrep sshd | xargs protect -dip"
86.Pp
87Remove protection from all current and future processes:
88.Pp
89.Dl "protect -cdi -p 1"
90.Pp
91Using
92.Xr ps 1
93to check if the protect flag has been applied to the process:
94.Pp
95.Dl "ps -O flags,flags2 -p 64430"
96.Pp
97.Dl " PID        F       F2 TT  STAT    TIME COMMAND"
98.Dl "64430 10104002 00000001  5  S+   0:00.00 ./main"
99.Dl "        ^P            ^PI"
100.Pp
101In the above example
102.Nm P
103points at the protected flag and
104.Nm PI
105points at the inheritance flag.
106The process is protected if
107.Nm P
108bit is set to 1.
109All children of this process will also be protected if
110.Nm PI
111bit is set to 1.
112.Sh SEE ALSO
113.Xr ps 1 ,
114.Xr procctl 2 ,
115.Xr rc.conf 5
116.Sh BUGS
117If you protect a runaway process that allocates all memory the system will
118deadlock.
119