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

pidof

Print the PIDs of a running program, by its exact name.

المستوى
لينكس اليومي
المجموعة
العمليات والمهام
يحتاج root
لا
الحزمة
procps-ng

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

ماذا يفعل

pidof NAME prints the PIDs of all processes of that program, on one line. Unlike pgrep, the name must match exactly (no pattern). It is often used inside other commands: kill $(pidof myapp).

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

pidof [OPTION]... PROGRAM...

الخيارات 13

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

-s
Only one PID.
-x
Also scripts (the shell that runs the script).
-o PID
Leave out this PID (%PPID = the calling shell).
-c
Only processes with the same root folder (root only).
-n
Do not call stat on network file systems.
-q
Quiet: only the exit code.
-z
Also zombies and processes in disk wait.
-d SEP
Separator between PIDs (default space).
-S SEP
Same as -d (procps-ng).
-t
Show thread IDs (procps-ng).
-w
Also kernel workers (procps-ng).
-h, --help
Show help.
-V, --version
Show the version.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1PIDs of a program

    pidof sshd
    2215 2210 1010

    All sshd processes.

  2. 2Only one PID

    pidof -s chronyd
    812

    For commands that take one PID.

  3. 3Use it with kill or renice

    kill -HUP $(pidof rsyslogd)

    Reload by name.

  4. 4Find a running script

    pidof -x backup.sh

    Without -x scripts are not found.

  5. 5Is it running? (scripts)

    pidof -q httpd && echo "httpd runs"

    Exit code 0 when found.

  6. 6Leave out the own shell

    pidof -o %PPID -x myscript.sh

    A script that checks if another copy runs.

  7. 7Comma separated for other tools

    pidof -d, httpd
    1420,1421,1422

    Handy for top -p.

  8. 8Watch all processes of a program

    top -p $(pidof -d, httpd)

    Only the web server.

  9. 9Threads of a process

    ps -L -p $(pidof chronyd)

    pidof gives the PID, ps the threads.

  10. 10Check that a service is not running twice

    pidof myapp | wc -w

    More than 1 for a single-instance app = a problem.

رموز الخروج

0 :: At least one process found. 1 :: Nothing found.

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

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

في الطرفية: man 8 pidof