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

pidof

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

Niveau
Dagelijks Linux
Groep
Processen en jobs
Root nodig
Nee
Pakket
procps-ng

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

Wat het doet

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

Zo schrijf je het

pidof [OPTION]... PROGRAM...

Opties 13

Meest gebruikt

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

Voorbeelden 10

$ als gewone gebruiker# als root (of met 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.

Exitcodes

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

Volledige handleiding

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

In je terminal: man 8 pidof