·터미널 명령어

pgrep

프로세스·시스템

쓰는 꼴

pgrep [-f] <pattern>

pkill과 똑같은 규칙으로 맞는 프로세스의 PID만 찍어 줍니다 — 그래서 죽이기 전에 무엇이 걸리는지 확인하는 연습 삼기에 딱 맞습니다.

자주 쓰는 옵션

옵션
-fMatch the full command line, so arguments count too.
-aPrint the command line next to the PID (Linux).
-lPrint the process name next to the PID.
-xExact name match only.
-u <user>Restrict to one user.
-cPrint how many matched instead of the PIDs.
-n / -oNewest / oldest match only.

예시

pgrep -af node

Every node process with its full command line.

pgrep -x sshd

The PID of sshd itself, not of anything merely mentioning ssh.

kill $(pgrep -f "celery worker")

Stop the processes the pattern found.

무엇이 돌고 있고 무엇이 자원을 먹는지 봅니다. 죽이기 전에 무엇인지 확인하는 것이 순서입니다.

읽는 방법

  • 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
  • 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
  • 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.

자주 묻는 것

Q. pgrep은 무엇을 하나요?

pkill과 똑같은 규칙으로 맞는 프로세스의 PID만 찍어 줍니다 — 그래서 죽이기 전에 무엇이 걸리는지 확인하는 연습 삼기에 딱 맞습니다.

Q. 어떻게 치나요?

pgrep [-f] <pattern> — 대괄호는 생략할 수 있는 자리입니다.

Q. 옵션은 몇 개나 자주 쓰나요?

여기 정리한 것은 7개입니다. 전체 목록은 man pgrep에 있습니다. 이 명령은 프로세스·시스템 갈래입니다.

같이 보는 명령

man 페이지: man pgrep