Safely Target Processes with skill and snice on Linux
You will finish with a cautious way to select Linux processes by PID, user, terminal or command, preview a signal or priority change, and then apply it only when the match is clear. The examples use procps 2:4.0.4-4ubuntu3.3, which provides procps-ng 4.0.4 on this machine.
The route
Jump straight to the step you need, or tick off Done means at the end.
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 commands 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. The -p option 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. The important parts are that the preview reports the intended process and that no signal is sent. -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. You can name a signal as -TERM, -SIGTERM or its number. 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 using 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 a terminal, and -c a command name. The selector 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. For example, selecting a user's terminal 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 range 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. To restore the original value, run renice with the value you recorded before changing it. Record that value first:
$ 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. 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 have more familiar separation between finding processes and acting on them, which reduces the chance that a changed command line selects the wrong workload.
Done means
- You confirmed the procps version and the command path.
- You previewed every PID, user, terminal or command selector with
-n. - You checked the live process immediately before sending a signal.
- You treated
TERMas disruptive and avoidedKILLunless there was a clear emergency. - You recorded the original niceness before using
sniceand know how to restore it.