IT 공부내용 정리/Linux

터미널 명령어 - pgrep 프로세스를 찾고 싶을 때

따뜻한 차가움 2025. 3. 13. 16:19

사용 버전 : Linux 우분투(레드햇 계열) 24.04.01 LTS 버전
사용한 시스템 지역/언어 : 대한민국/한글

man pgrep 원문

더보기

PGREP(1)                         User Commands                        PGREP(1)

NAME
       pgrep, pkill, pidwait - look up, signal, or wait for processes based on
       name and other attributes

SYNOPSIS
       pgrep [options] pattern
       pkill [options] pattern
       pidwait [options] pattern

DESCRIPTION
       pgrep  looks  through  the  currently  running  processes and lists the
       process IDs which match the selection criteria to stdout.  All the cri‐
       teria have to match.  For example,

              $ pgrep -u root sshd

       will only list the processes called sshd AND owned  by  root.   On  the
       other hand,

              $ pgrep -u root,daemon

       will list the processes owned by root OR daemon.

       pkill  will  send  the  specified  signal  (by default SIGTERM) to each
       process instead of listing them on stdout.

       pidwait will wait for each process instead of listing them on stdout.

OPTIONS
       -signal
       --signal signal
              Defines the signal to send to each matched process.  Either  the
              numeric  or  the  symbolic  signal name can be used. In pgrep or
              pidwait mode only the long option can be used and has no  effect
              unless  used  in conjunction with --require-handler to filter to
              processes with a userspace signal handler present for a particu‐
              lar signal.

       -c, --count
              Suppress normal  output;  instead  print  a  count  of  matching
              processes.   When  count  does  not match anything, e.g. returns
              zero, the command will return  non-zero  value.  Note  that  for
              pkill   and  pidwait,  the  count  is  the  number  of  matching
              processes, not the processes that were successfully signaled  or
              waited for.

       -d, --delimiter delimiter
              Sets  the  string  used to delimit each process ID in the output
              (by default a newline).  (pgrep only.)

       -e, --echo
              Display name and PID of the process being killed.  (pkill only.)

       -f, --full
              The pattern is normally only matched against the  process  name.
              When -f is set, the full command line is used.

       -g, --pgroup pgrp,...
              Only  match  processes in the process group IDs listed.  Process
              group 0 is translated into pgrep's, pkill's,  or  pidwait's  own
              process group.

       -G, --group gid,...
              Only  match processes whose real group ID is listed.  Either the
              numerical or symbolical value may be used.

       -i, --ignore-case
              Match processes case-insensitively.

       -l, --list-name
              List the process name as well as the process ID.  (pgrep only.)

       -a, --list-full
              List the full command line as well as the  process  ID.   (pgrep
              only.)

       -n, --newest
              Select  only  the newest (most recently started) of the matching
              processes.

       -o, --oldest
              Select only the oldest (least recently started) of the  matching
              processes.

       -O, --older secs
              Select processes older than secs.

       -P, --parent ppid,...
              Only match processes whose parent process ID is listed.

       -s, --session sid,...
              Only  match  processes whose process session ID is listed.  Ses‐
              sion ID 0 is translated into pgrep's, pkill's, or pidwait's  own
              session ID.

       -t, --terminal term,...
              Only  match processes whose controlling terminal is listed.  The
              terminal name should be specified without the "/dev/" prefix.

       -u, --euid euid,...
              Only match processes whose effective user ID is listed.   Either
              the numerical or symbolical value may be used.

       -U, --uid uid,...
              Only  match  processes whose real user ID is listed.  Either the
              numerical or symbolical value may be used.

       -v, --inverse
              Negates the matching.  This option is usually used in pgrep's or
              pidwait's context.  In pkill's context the short option is  dis‐
              abled to avoid accidental usage of the option.

       -w, --lightweight
              Shows  all  thread  ids  instead of pids in pgrep's or pidwait's
              context.  In pkill's context this option is disabled.

       -x, --exact
              Only match processes whose names (or  command  lines  if  -f  is
              specified) exactly match the pattern.

       -F, --pidfile file
              Read  PIDs  from  file.  This option is more useful for pkill or
              pidwait than pgrep.

       -L, --logpidfile
              Fail if pidfile (see -F) not locked.

       -r, --runstates D,R,S,Z,...
              Match only processes which match the process state.

       -A, --ignore-ancestors
              Ignore all ancestors of pgrep, pkill, or pidwait.  For  example,
              this can be useful when elevating with sudo or similar tools.

       -H, --require-handler
              Only match processes with a userspace signal handler present for
              the signal to be sent.

       --cgroup name,...
              Match on provided control group (cgroup) v2 name. See cgroups(8)

       --ns pid
              Match  processes that belong to the same namespaces. Required to
              run as root to match processes from other  users.  See  --nslist
              for how to limit which namespaces to match.

       --nslist name,...
              Match  only  the provided namespaces. Available namespaces: ipc,
              mnt, net, pid, user, uts.

       -q, --queue value
              Use sigqueue(3) rather than kill(2) and the  value  argument  is
              used  to  specify  an integer to be sent with the signal. If the
              receiving process has installed a handler for this signal  using
              the  SA_SIGINFO  flag  to  sigaction(2), then it can obtain this
              data via the si_value field of the siginfo_t structure.

       -V, --version
              Display version information and exit.

       -h, --help
              Display help and exit.

OPERANDS
       pattern
              Specifies an Extended Regular Expression  for  matching  against
              the process names or command lines.

EXAMPLES
       Example 1: Find the process ID of the named daemon:

              $ pgrep -u root named

       Example 2: Make syslog reread its configuration file:

              $ pkill -HUP syslogd

       Example 3: Give detailed information on all xterm processes:

              $ ps -fp $(pgrep -d, -x xterm)

       Example 4: Make all chrome processes run nicer:

              $ renice +4 $(pgrep chrome)

EXIT STATUS
       0      One  or  more processes matched the criteria. For pkill and pid‐
              wait, one or more processes must  also  have  been  successfully
              signalled or waited for.
       1      No processes matched or none of them could be signalled.
       2      Syntax error in the command line.
       3      Fatal error: out of memory etc.

NOTES
       The  process  name  used  for  matching is limited to the 15 characters
       present in the output of /proc/pid/stat.  Use the -f  option  to  match
       against  the  complete command line, /proc/pid/cmdline. Threads may not
       have the same process name as the parent process but will have the same
       command line.

       The running pgrep, pkill, or pidwait process will never  report  itself
       as a match.

       The  -O  --older option will silently fail if /proc is mounted with the
       subset=pid option.

BUGS
       The options -n and -o and -v can not be combined.  Let me know  if  you
       need to do this.

       Defunct processes are reported.

       pidwait  requires the pidfd_open(2) system call which first appeared in
       Linux 5.3.

SEE ALSO
       ps(1), regex(7), signal(7), sigqueue(3), killall(1), skill(1), kill(1),
       kill(2), cgroups(8).

AUTHOR
       Kjetil Torgrim Homme

REPORTING BUGS
       Please send bug reports to procps@freelists.org

procps-ng                         2023-01-16                          PGREP(1)

man  번역기 번역본

더보기

pgrep (1) 사용자 명령 pgrep (1)

이름
       PGREP, PKILL, PIDWAIT-
       이름 및 기타 속성

개요
       pgrep [옵션] 패턴
       pkill [옵션] 패턴
       Pidwait [옵션] 패턴

설명
       PGREP는 현재 실행중인 프로세스를 살펴보고
       선택 기준과 STDOUT에 일치하는 프로세스 ID.  모든 크리
       테리아는 일치해야합니다.  예를 들어,

$ pgrep -u 루트 sshd

SSHD라는 프로세스 만 나열하고 루트가 소유 한 프로세스 만 나열합니다.   에
       반면,

$ pgrep -u 루트, 데몬

루트 또는 데몬이 소유 한 프로세스를 나열합니다.

pkill은 지정된 신호 (기본적으로 sigterm)를 각각에 보냅니다.
       stdout에 나열하는 대신 프로세스하십시오.

Pidwait은 Stdout에 나열하는 대신 각 프로세스를 기다립니다.

옵션
       -신호
       -신호 신호
              일치하는 각 프로세스로 보낼 신호를 정의합니다.  어느 쪽이든
              숫자 또는 기호 신호 이름을 사용할 수 있습니다. pgrep 또는
              Pidwait 모드는 긴 옵션 만 사용할 수 있으며 영향을 미치지 않습니다.
              -require-handler와 함께 사용하지 않는 한
              사용자 공간 신호 핸들러가 포함 된 프로세스는
              LAR 신호.

-c, -카운트
              정상 출력을 억제하십시오.  대신 일치 카운트를 인쇄하십시오
              프로세스.   카운트가 아무 것도 일치하지 않는 경우 (예 : 보고
              0, 명령은 0이 아닌 값을 반환합니다.  주목하십시오
              pkill과 pidwait, count는 일치하는 수입니다.
              성공적으로 신호를받은 프로세스가 아니라 프로세스
              기다렸다.

-d, -벨리 미터 구분 기
              출력에서 각 프로세스 ID를 구분하는 데 사용되는 문자열을 설정합니다.
              (기본적으로 Newline).  (pgrep 만.)

-e, -echo
              사망중인 프로세스의 이름과 PID를 표시합니다.  (pkill 만.)

-f, --full
              패턴은 일반적으로 프로세스 이름과 일치합니다.
              -f가 설정되면 전체 명령 줄이 사용됩니다.

-g, -pgroup pgrp, ...
              나열된 프로세스 그룹 ID의 프로세스 만 일치합니다.  프로세스
              그룹 0은 pgrep, pkill 's 또는 Pidwait's로 번역됩니다.
              프로세스 그룹.

-g, -group gid, ...
              실제 그룹 ID가 나열된 프로세스 만 일치합니다.  어느 쪽이든
              수치 적 또는 상징적 값이 사용될 수 있습니다.

-i, -ignore-case
              일치 프로세스는 비면적으로 처리합니다.

-l,-list-name
              프로세스 ID뿐만 아니라 프로세스 이름을 나열하십시오.  (pgrep 만.)

-a,-list-full
              전체 명령 줄과 프로세스 ID를 나열하십시오.   (PGREP
              오직.)

-n, -새로운 것
              일치하는 최신 (가장 최근에 시작된) 만 선택하십시오.
              프로세스.

-O, -가장
              일치하는 가장 오래된 (최근에 시작된 가장 최근에 시작) 만 선택하십시오.
              프로세스.

-O, -older Secs
              SEC보다 오래된 프로세스를 선택하십시오.

-p, -parent ppid, ...
              부모 프로세스 ID가 나열된 프로세스 만 일치합니다.

-s, -session sid, ...
              프로세스 세션 ID가 나열된 프로세스 만 일치합니다.  ses-
              sion id 0
              세션 ID.

-t, -터미널 용어, ...
              제어 터미널이 나열된 일치 프로세스 만 일치합니다.  그만큼
              "/dev/"접두사없이 터미널 이름을 지정해야합니다.

-u, -euid euid, ...
              효과적인 사용자 ID가 나열된 프로세스 만 일치합니다.   어느 하나
              수치 적 또는 상징적 값이 사용될 수 있습니다.

-U, -uid uid, ...
              실제 사용자 ID가 나열된 프로세스 만 일치합니다.  어느 쪽이든
              수치 적 또는 상징적 값이 사용될 수 있습니다.

-v, -interverse
              일치하는 것을 무효화합니다.  이 옵션은 일반적으로 PGREP OR에서 사용됩니다
              Pidwait의 맥락.  Pkill의 맥락에서 짧은 옵션은 dis-
              우발적 인 옵션 사용을 피하기 위해 ABLED.

-w, --- 라이트 중량
              pgrep 또는 pidwait 's의 PID 대신 모든 스레드 ID를 표시합니다.
              문맥.  Pkill의 맥락 에서이 옵션은 비활성화됩니다.

-x, --exact
              이름 (또는 -f 인 경우 명령 줄
              지정) 패턴과 정확히 일치합니다.

-f, --pidfile 파일
              파일에서 PID를 읽습니다.  이 옵션은 pkill 또는에 더 유용합니다
              pgrep보다 pidwait.

-l, -logpidfile
              pidfile (-f 참조)이 잠겨 있지 않으면 실패합니다.

-r, -runstates d, r, s, z, ...
              프로세스 상태와 일치하는 프로세스 만 일치합니다.

-a, -ignore-anfestors
              PGREP, PKILL 또는 PIDWAIT의 모든 조상을 무시하십시오.  예를 들어,
              이것은 Sudo 또는 유사한 도구를 사용하여 유용 할 수 있습니다.

-h,-require handler
              사용자 공간 신호 핸들러와 프로세스 만 일치
              전송 될 신호.

--cgroup 이름, ...
              제공된 제어 그룹 (CGROUP) v2 이름에서 일치합니다. CGROUPS 참조 (8)

-NS PID
              동일한 네임 스페이스에 속하는 프로세스를 일치시킵니다. 필요합니다
              다른 사용자의 프로세스와 일치하는 루트로 실행됩니다.  -nslist를 참조하십시오
              일치 할 네임 스페이스를 제한하는 방법.

-nslist 이름, ...
              제공된 네임 스페이스 만 일치합니다. 사용 가능한 네임 스페이스 : IPC,
              Mnt, Net, PID, 사용자, UTS.

-Q, -Queue 값
              죽이기 대신 sigqueue (3)를 사용하고 가치 주장은 다음과 같습니다.
              신호로 전송 될 정수를 지정하는 데 사용됩니다. 만약
              수신 프로세스는이 신호를 사용하여 처리 된 핸들러를 설치했습니다.
              SA_SIGINFO 플래그에서 SIGACTION (2)를 얻을 수 있습니다.
              siginfo_t 구조의 si_value 필드를 통한 데이터.

-v, -버전
              버전 정보 및 종료.

-h, -help
              도움말과 종료를 표시하십시오.

피연산자
       무늬
              일치하는 연장 된 정규 표현식을 지정합니다
              프로세스 이름 또는 명령 줄.


       예 1 : 명명 된 데몬의 프로세스 ID 찾기 :

$ pgrep -u 루트 명명

예제 2 : syslog 만들기 구성 파일을 다시 읽습니다.

$ pkill -hup syslogd

예 3 : 모든 Xterm 프로세스에 대한 자세한 정보 제공 :

$ ps -fp $ (pgrep -d, -x xterm)

예 4 : 모든 크롬 프로세스를 더 잘 실행하게합니다.

$ Renice +4 $ (PGREP Chrome)

종료 상태
       0 하나 이상의 프로세스가 기준과 일치했습니다. pkill과 pid-
              잠깐만, 하나 이상의 프로세스도 성공적으로
              신호를 보내거나 기다렸다.
       1 과정이 일치하지 않거나 그 중 어느 것도 신호를 보낼 수 없습니다.
       2 명령 줄의 구문 오류.
       3 치명적 오류 : 기억이 나지 않습니다.

메모
       일치하는 데 사용되는 프로세스 이름은 15 자로 제한됩니다.
       /proc/pid/stat의 출력에 존재합니다.  -f 옵션을 사용하여 일치하십시오
       전체 명령 줄에 대해/Proc/Pid/Cmdline. 스레드는 그렇지 않을 수 있습니다
       상위 프로세스와 동일한 프로세스 이름을 가지지 만 동일합니다.
       명령 줄.

실행중인 PGREP, PKILL 또는 PIDWAIT 프로세스는 절대보고하지 않습니다.
       경기로.

-O-Older 옵션이 조용히 실패하면 /Proc가
       서브 세트 = PID 옵션.

버그
       옵션 -n 및 -o 및 -v를 결합 할 수 없습니다.  당신이 있는지 알려주세요
       이 작업을 수행해야합니다.

소멸 된 프로세스 가보고됩니다.

Pidwait에는 Pidfd_open (2) 시스템 호출이 처음 나타났습니다.
       리눅스 5.3.

참조하십시오
       PS (1), Regex (7), 신호 (7), Sigqueue (3), Killall (1), Skill (1), Kill (1),
       킬 (2), cgroups (8).

작가
       Kjetil Torgrim Homme

보고 버그
       procps@freelists.org로 버그 보고서를 보내주십시오

2023-01-16 PGRE의 Procps (1)

 

형태 : pgrep [옵션] [패턴]

기능 : 지정한  [패턴]과 일치하는 프로세스의 정보를 출력한다.

 

[옵션]

-x : 패턴과 정확히 일치하는 프로세스의 정보를 출력한다.

-n : 패턴을 포함하고 있는 가장 최근 프로세스의 정보를 출력한다.

-u [사용자이름] : [사용자이름]에 해당하는 사용자의 모든 프로세스를 출력한다.

-l : PID와 프로세스 이름을 출력한다.

-t term : 특정 단말기와 관련된 프로세스의 정보를 출력한다.

 

grep이 파일 내부의 문자를 검색하는 기능을 가졌다면 pgrep은 prosses + grep인 셈이다.

프로세스에서 내가 찾는 대상이 있는지 확인해주는 기능으로 프로세스가 너무 많아서 찾기 힘들 때 혹은 원하는 대상이 명확할 때 사용해볼 수 있겠다