Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

pkill

Find processes by name or other attributes (pgrep), signal them (pkill), or wait for them to end (pidwait).

Niveau
RHCSA-examen
Groep
Processen en jobs
Root nodig
Voor wijzigingen
Pakket
procps-ng
Ook
pgrep, pidwait

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

pgrep PATTERN prints the PIDs of processes whose name matches the pattern (a regular expression). pkill PATTERN sends them a signal (TERM by default). Both select with the same options: by user (-u), terminal (-t), parent (-P), full command line (-f) and more.

Run pgrep first with the same options to see what pkill would hit.

Zo schrijf je het

pgrep [OPTION]... PATTERN
pkill [OPTION]... [-SIGNAL] PATTERN
pidwait [OPTION]... PATTERN

Opties 32

Meest gebruikt

Signal (pkill)

-SIGNAL, --signal SIGNAL
The signal to send (default TERM).
-e, --echo
Show what was killed.
-q, --queue VALUE
Send a value with the signal.
-H, --require-handler
Only processes that handle the signal.

Output (pgrep)

-l, --list-name
Show the name with the PID.
-a, --list-full
Show the full command line.
-c, --count
Only the number of matches.
-d, --delimiter TEXT
Separator between PIDs.
-w, --lightweight
Show thread IDs.

Select

-f, --full
Match the whole command line, not only the name.
-u, --euid USERS
Effective user.
-U, --uid USERS
Real user.
-G, --group GIDS
Real group.
-g, --pgroup PGRPS
Process group.
-s, --session SIDS
Session.
-t, --terminal TERMS
Terminal, like pts/1.
-P, --parent PPIDS
Children of these parents.
-n, --newest
Only the newest match.
-o, --oldest
Only the oldest match.
-O, --older SECONDS
Only processes older than this.
-x, --exact
The name must match exactly.
-i, --ignore-case
Ignore case.
-v, --inverse
Everything that does not match.
-r, --runstates STATES
Only these states (D, R, S, Z …).
-A, --ignore-ancestors
Leave out the own parents.
-F, --pidfile FILE
Read PIDs from a file.
-L, --logpidfile
Fail if the PID file is not locked.
--cgroup NAMES
Only these cgroups.
--ns PID
Same namespaces as PID.
--nslist NAMES
Which namespaces to compare.
-h, --help
Show help.
-V, --version
Show the version.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Find PIDs by name

    pgrep -l sshd
    1010 sshd
    2210 sshd

    -l adds the name.

  2. 2See full command lines

    pgrep -a python3

    Find which script is running.

  3. 3Stop all processes of a user

    pkill -u olduser

    Before you delete the account.

  4. 4Log out a session

    pkill -KILL -t pts/3

    Ends everything on that terminal.

  5. 5Match the full command line

    pgrep -af 'backup.sh'
    pkill -f 'backup.sh'

    The process name is bash; -f finds the script.

  6. 6Count processes

    pgrep -c httpd
    6

    Quick health check.

  7. 7Wait until a process is gone

    pidwait -f backup.sh; echo "backup finished"

    Then start the next step.

  8. 8Reload a daemon by name

    pkill -HUP rsyslogd

    Re-reads the config.

  9. 9The newest or oldest match

    pgrep -n firefox; pgrep -o httpd

    -o httpd = the parent of all httpd children.

  10. 10Hunt processes that run from /tmp (security)

    pgrep -af '/tmp/|/dev/shm/'

    Suspicious locations for running programs.

  11. 11Show what pkill did

    pkill -e dd
    dd killed (pid 4123)

    Proof of the action.

Let op

  • The pattern is a regular expression and matches part of the name: pkill ssh also hits ssh-agent and sshd. Use -x for an exact name.
  • Test with pgrep (same options) before pkill.

Exitcodes

0 :: At least one process matched. 1 :: No process matched. 2 :: Syntax error. 3 :: Fatal error.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man pkill