Home / Alt manpages / skill(1)

  • skill(1)
  • User command
  • linux

Safely Target Processes with skill and snice on Linux

One typo in a process selector and skill can send a signal to the wrong workload, so you stay in preview mode until the match is certain. You will select processes by PID, user, terminal or command, preview a signal or priority change, and apply it only once the match is clear. The examples use procps 2:4.0.4-4ubuntu3.3, which provides procps-ng 4.0.4 on this machine.

Allow about fifteen minutes. You need a shell and a process you are authorised to inspect or control. Reading help, listing signals and using -n are ordinary commands. Sending signals to another user's process, stopping a process, or assigning a negative priority normally requires elevated privileges and can disrupt work or services.

1. Confirm the installed commands

skill and snice are two names for the same procps tool family: skill sends a signal, snice changes process niceness. The local manual describes both as obsolete and unportable, so prefer pkill, pgrep, killall or renice for new scripts when their clearer interfaces fit.

$ command -v skill snice
/usr/bin/skill
/usr/bin/snice
$ skill --version
skill from procps-ng 4.0.4
$ snice --version
snice from procps-ng 4.0.4

Checkpoint

If either command is missing, install or repair the distribution package that supplies procps before continuing. Do not copy examples from a different implementation and assume its selection syntax is identical.

2. Preview a selection by PID

The safest first test selects one known process and asks for no action. The shell's $$ expands to the current shell PID, and -p tells skill or snice to interpret the next expression as a PID.

$ skill -n -v -p $$
?        YOUR_USER  YOUR_PID bash               Success
$ printf 'preview status: %s\n' "$?"
preview status: 0

The username, PID and command vary. What matters is that the preview reports the intended process and sends no signal. -n means no action: it simulates the event without changing the system. Keep -n in place while testing a new selector.

Checkpoint

Confirm the PID independently before replacing the placeholder in an operational command:

$ ps -p YOUR_PID -o pid=,user=,comm=
 YOUR_PID YOUR_USER bash

Replace YOUR_PID and YOUR_USER with values from your own machine. A PID can be reused after a process exits, so inspect it immediately before sending a signal.

3. List signals and choose a reversible first action

Use the installed command to see the signal names it accepts:

$ skill -L
 1 HUP      2 INT     3 QUIT    4 ILL     5 TRAP    6 ABRT    7 BUS
 8 FPE      9 KILL   10 USR1   11 SEGV   12 USR2   13 PIPE   14 ALRM
15 TERM    16 STKFLT 17 CHLD   18 CONT   19 STOP   20 TSTP   21 TTIN
22 TTOU    23 URG    24 XCPU   25 XFSZ   26 VTALRM 27 PROF   28 WINCH
29 POLL    30 PWR    31 SYS

The exact spacing can differ with terminal width. The default signal for skill is TERM, which asks a process to terminate cleanly. Name a signal as -TERM, -SIGTERM or its number.

Warning

Do not start with KILL. It cannot be caught or cleaned up by the target, and it gives you no graceful recovery path.

To practise without changing state, preview a signal against the known PID:

$ skill -n -v -TERM -p YOUR_PID
?        YOUR_USER  YOUR_PID bash               Success

When you have checked the process twice and accept the interruption, remove only -n:

$ skill -v -TERM -p YOUR_PID
YOUR_USER YOUR_PID bash Success

There is no undo for a delivered TERM. Recovery means restarting the affected program or service through its normal procedure; for a service, use its service manager rather than selecting all matching processes by hand.

4. Select by user, terminal or command

Use an explicit selector option when the expression could be misunderstood:

  • -u selects a username.
  • -t selects a terminal.
  • -c selects a command name.

Any of these can match more than one process, so always preview first:

$ skill -n -v -TERM -u YOUR_USER
$ skill -n -v -TERM -t /dev/pts/7
$ skill -n -v -TERM -c YOUR_COMMAND

These commands print the matches without signalling them. Replace the placeholders with exact values from ps or tty. A command-name match is broader than a PID match: several instances, helper processes or an unrelated program with the same name may be selected.

Multiple selection expressions can be supplied, but broad matches are a common error trap. Selecting a user's terminal, for example, can affect every process attached to that terminal. Treat examples that target a terminal or a user as administrative operations, and inspect the complete preview before removing -n.

5. Change niceness with snice

snice uses the same selectors but changes scheduling priority instead of sending a signal. Its default priority adjustment is +4. Niceness values run from +20, the slowest end, to -20, the fastest end; negative values are restricted to administrative users.

$ snice -n -v +7 -p YOUR_PID
?        YOUR_USER  YOUR_PID bash               Success
$ printf 'preview status: %s\n' "$?"
preview status: 0

The output is implementation-specific in its spacing, so use it to verify the selected PID rather than to parse columns in a script. A positive adjustment reduces priority relative to the current value. Preview a change to a workload you own, then inspect the result with ps:

$ snice +7 -p YOUR_PID
$ ps -p YOUR_PID -o pid=,ni=,comm=
 YOUR_PID  7 bash

The niceness change applies to the process and may be inherited by children it starts. Record the original value before changing it, so you can restore it with renice:

$ ps -p YOUR_PID -o pid=,ni=,comm=
 YOUR_PID  0 bash
$ renice 0 -p YOUR_PID

Only use a negative value when you understand the workload and have the required privilege. Raising priority can starve other processes and is not a general performance fix.

6. Use namespace matching only when you mean it

The --ns PID form selects processes in the same namespace as another PID. The manual lists namespace types including ipc, mnt, net, pid, user and uts. This is an advanced boundary, especially on containers and service hosts.

$ skill --nslist
$ skill -n -v -TERM --ns YOUR_PID

Use --nslist ipc,mnt,net,pid,user,uts when you need to state which namespaces are considered, and verify the resulting list before taking action. If you only need one ordinary process, -p is easier to reason about.

7. Keep scripts predictable

For automation, capture the exit status and log the selector you used. A successful command status means the tool completed its operation; it does not make a broad selector safe. Start with -n during deployment checks, and replace it only after a human or a carefully tested policy has confirmed the match.

skill -n -v -TERM -p "$PID"
status=$?
if [ "$status" -ne 0 ]; then
    printf 'skill preview failed with status %s\n' "$status" &2
    exit "$status"
fi

For long-lived scripts, prefer the clearer modern tools named in the manual. They separate finding processes from acting on them more clearly, which reduces the chance that a changed command line selects the wrong workload.

Done means

  • Version confirmed: you checked the procps version and the command path.
  • Every selector previewed: PID, user, terminal or command, each with -n first.
  • Process rechecked: you confirmed the live process immediately before sending a signal.
  • TERM treated as disruptive: you avoided KILL unless there was a clear emergency.
  • Niceness recorded: you noted the original value before using snice and know how to restore it.