pgrep
Processus et système
Syntaxe
pgrep [-f] <pattern>N'affiche que les PID correspondant a un motif, selon les memes regles que pkill : c'est le test a blanc a faire avant de tuer quoi que ce soit.
Options courantes
| Option | Signification |
|---|---|
| -f | Match the full command line, so arguments count too. |
| -a | Print the command line next to the PID (Linux). |
| -l | Print the process name next to the PID. |
| -x | Exact name match only. |
| -u <user> | Restrict to one user. |
| -c | Print how many matched instead of the PIDs. |
| -n / -o | Newest / oldest match only. |
Exemples
pgrep -af nodeEvery node process with its full command line.
pgrep -x sshdThe PID of sshd itself, not of anything merely mentioning ssh.
kill $(pgrep -f "celery worker")Stop the processes the pattern found.
Ce qui tourne et ce qui mange la machine. Identifier vient avant tuer.
Comment lire
- Les crochets [ ] marquent une partie facultative.
- Les points de suspension … signifient qu’on peut en mettre plusieurs.
- Les options sont sensibles à la casse : sur certaines commandes, -r et -R ne font pas la même chose.
Questions fréquentes
Q. Que fait pgrep ?
N'affiche que les PID correspondant a un motif, selon les memes regles que pkill : c'est le test a blanc a faire avant de tuer quoi que ce soit.
Q. Comment l’écrire ?
pgrep [-f] <pattern> — les crochets marquent ce qui est facultatif.
Q. Combien d’options valent la peine ?
Il y en a 7 ici ; la liste complète est dans man pgrep. Cette commande relève de Processus et système.
Commandes liées
page man: man pgrep