الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

pkill

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

المستوى
امتحان RHCSA
المجموعة
العمليات والمهام
يحتاج root
للتغييرات
الحزمة
procps-ng
يُسمّى أيضًا
pgrep, pidwait

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

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

الخيارات 32

الأكثر استخدامًا

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.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع 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.

انتبه

  • 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.

رموز الخروج

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

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man pkill