PROTECT(1)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’– protect(1) β€” keep ur faves alive when swap says bye πŸ’–

okay bestie, welcome to PROTECT(1) from the General Commands Manual. This is the page about marking processes as protected so the kernel doesn't just yeet them when swap space runs out. Iconic survival behavior, honestly. 🫢


✨ NAME ✨

protect β€” protect processes from being killed when swap space is exhausted


🌸 SYNOPSIS 🌸

protect [-i] command
protect [-cdi] -g pgrp
protect [-cdi] -p pid

πŸ¦‹ DESCRIPTION πŸ¦‹

The protect command is literally here to mark processes as protected. When swap space is exhausted, the kernel does not kill protected processes. That's the whole vibe. πŸ’…

Heads up bestie: this protected state is not inherited by child processes by default. So don't assume the baby processes get the same armor for free. πŸ™ˆ

The options are:

  • -c β€” remove protection from the specified processes. rip their little safety bubble 😭
  • -d β€” apply the operation to all current children of the specified processes.
  • -i β€” apply the operation to all future children of the specified processes.
  • -g pgrp β€” apply the operation to all processes in the specified process group.
  • -p pid β€” apply the operation to the specified process.
  • command β€” execute command as a protected process. main character energy from the jump ✨
Also note: when you're adjusting the state of existing processes, you may specify only one of -p or -g. Don't try to do both, bestie, it's not that kind of party.

Daemons can be protected on startup using the ⟨name⟩_oomprotect option from rc.conf(5). Cute, right? πŸŽ€


🌈 EXIT STATUS 🌈

The protect utility exits 0 on success, and >0 if an error occurs. Slay when it works, side-eye when it doesn't. πŸ’€


πŸ“ EXAMPLES πŸ“

Mark the Xorg server as protected:

pgrep Xorg | xargs protect -p

Protect all ssh sessions and their child processes:

pgrep sshd | xargs protect -dip

Remove protection from all current and future processes:

protect -cdi -p 1

Using ps(1) to check if the protect flag has been applied to the process:

ps -O flags,flags2 -p 64430

 PID        F       F2 TT  STAT    TIME COMMAND
64430 10104002 00000001  5  S+   0:00.00 ./main
       ^P            ^PI

In the above example, P points at the protected flag and PI points at the inheritance flag. The process is protected if the P bit is set to 1. All children of this process will also be protected if the PI bit is set to 1. iykyk πŸ‘‘


πŸ”₯ DIAGNOSTICS πŸ”₯

protect: procctl: Operation not permitted

The protect command does not have the required permissions to protect selected processes. There are many reasons why this could be the case, e.g.:

  • protect is not executed by root.
  • protect is executed inside a jail(8), which is not supported at the moment.

So yeah, if you're not root or you're in jail, this is giving nope. 😭


⭐ SEE ALSO ⭐

ps(1), procctl(2), rc.conf(5)


πŸ’€ BUGS πŸ’€

If you protect a runaway process that allocates all memory, the system will deadlock.

bestie that is not a vibe. do not do that. 🫢

this iconic little page is PROTECT(1), General Commands Manual, from the Debian crew β€” dated July 12, 2022. mwah πŸ’–βœ¨

πŸ“¦ where this page comes from