pgrep and pkill
noun
say it: “pee-grep and pee-kill” /ˈpiɡrɛp ənd ˈpikɪl/
Two commands that find running programs by name: pgrep lists them and pkill sends them a signal, usually to stop.
What do pgrep and pkill do?
pgrep finds running programs by name and prints their PIDs; -a adds each one's command line. pkill sends the same matches a signal, TERM unless you name another. -f matches the whole command line, which a script needs, since its name comes after bash. Run pgrep first, so you see what pkill would stop.
pgrep -af alarm # 2781 bash ./alarm.sh
pkill -f alarm # asks every match to stop
pgrep -af alarm # nothing: it's gone
In a sentence
- “With pgrep and pkill, Sam stopped the alarm by name without looking up its number.”
- “Check with pgrep first; pgrep and pkill match the same names.”
Level: Journeyman · More Unix terms at this level
Updated