ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Linux] ps
    서버 2016. 11. 3. 17:49

    프로세스의 상태를 확인하는 명령어. 

     주로 서버의 상태를 파악하기 위하여 프로세스의 상태를 관리자가 파악할때에 사용하는 명령어

    사용형식

    $ ps [options] 

    사용 예시

    #1

    $ ps
    PID TTY          TIME CMD
      823 pts/0    00:00:00 bash
     1545 pts/0    00:00:00 ps

    아무런 옵션이 주어지지 않으면 현재 사용자가 실행시킨 프로세스만을 보여줍니다. 즉, 위의 결과로 보면 현재 ps를 실행시킨 사용자는 bash쉘을 사용 중 ps를 실행시킨 것을 알 수 있습니다.

    #2

    $ ps -ef
    UID        PID  PPID  C STIME TTY          TIME CMD
    root         1     0  0 10:35 ?        00:00:04 init
    root         2     1  0 10:35 ?        00:00:00 [keventd]
    root         3     1  0 10:35 ?        00:00:00 [kapmd]
    root         4     1  0 10:35 ?        00:00:00 [ksoftirqd_CPU0]
    root         5     1  0 10:35 ?        00:00:00 [kswapd]
    root         6     1  0 10:35 ?        00:00:00 [bdflush]
    root         7     1  0 10:35 ?        00:00:00 [kupdated]
    root         8     1  0 10:35 ?        00:00:00 [mdrecoveryd]
    root        12     1  0 10:35 ?        00:00:00 [kjournald]
    root        64     1  0 10:35 ?        00:00:00 [khubd]
    root       156     1  0 10:35 ?        00:00:00 [kjournald]
    root       444     1  0 10:36 ?        00:00:00 [eth1]
    root       491     1  0 10:36 ?        00:00:00 syslogd -m 0
    root       495     1  0 10:36 ?        00:00:00 klogd -x
    rpc        506     1  0 10:36 ?        00:00:00 portmap
    rpcuser    525     1  0 10:36 ?        00:00:00 rpc.statd
    root       604     1  0 10:36 ?        00:00:00 /usr/sbin/apmd -p 10 -w 5 -W -P /etc/sysconfig/apm-scripts/apmscript
    root       642     1  0 10:36 ?        00:00:01 /usr/sbin/sshd
    root       656     1  0 10:36 ?        00:00:00 xinetd -stayalive -reuse -pidfile /var/run/xinetd.pid
    root       679     1  0 10:36 ?        00:00:00 sendmail: accepting connections
    smmsp      689     1  0 10:36 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
    root       699     1  0 10:36 ?        00:00:00 gpm -t ps/2 -m /dev/mouse
    root       708     1  0 10:36 ?        00:00:00 crond
    xfs        741     1  0 10:36 ?        00:00:00 xfs -droppriv -daemon
    daemon     759     1  0 10:36 ?        00:00:00 /usr/sbin/atd
    root       768     1  0 10:36 tty1     00:00:00 /sbin/mingetty tty1
    root       769     1  0 10:36 tty2     00:00:00 /sbin/mingetty tty2
    root       770     1  0 10:36 tty3     00:00:00 /sbin/mingetty tty3
    root       771     1  0 10:36 tty4     00:00:00 /sbin/mingetty tty4
    root       772     1  0 10:36 tty5     00:00:00 /sbin/mingetty tty5
    root       773     1  0 10:36 tty6     00:00:00 /sbin/mingetty tty6
    root       774     1  0 10:36 ?        00:00:00 /usr/bin/gdm-binary -nodaemon
    root       807   774  0 10:36 ?        00:00:00 /usr/bin/gdm-binary -nodaemon
    root       808   807  0 10:36 ?        00:01:30 /usr/X11R6/bin/X :0 -auth /var/gdm/:0.Xauth
    gdm        820   807  0 10:36 ?        00:00:02 /usr/bin/gdmgreeter
    root       821   642  0 10:37 ?        00:00:00 /usr/sbin/sshd
    root       823   821  0 10:37 pts/0    00:00:00 -bash
    root      1562   823  0 18:14 pts/0    00:00:00 ps -ef

    -e 옵션은 모든 프로세스를 표시해주는 옵션이며, -f 옵션은 전체경로로 프로세스를 표시해주는 옵션입니다. 따라서 모든 프로세스를 자세하게 보려고 할 때에 사용하는 옵션입니다. 

    #3

    $ ps -ef | grep tty
    root       768     1  0 10:36 tty1     00:00:00 /sbin/mingetty tty1
    root       769     1  0 10:36 tty2     00:00:00 /sbin/mingetty tty2
    root       770     1  0 10:36 tty3     00:00:00 /sbin/mingetty tty3
    root       771     1  0 10:36 tty4     00:00:00 /sbin/mingetty tty4
    root       772     1  0 10:36 tty5     00:00:00 /sbin/mingetty tty5
    root       773     1  0 10:36 tty6     00:00:00 /sbin/mingetty tty6
    root      1564   823  0 18:21 pts/0    00:00:00 grep tty

    위 #2번은 자세하게 확인할 수 있지만 너무 자세하게 모든 프로세스가 출력되어 사용자가 단번에 원하는 프로세스를 찾을 수 없습니다. 파이프라인과 grep명령어와 합쳐 다음과 같이 찾고자 하는 프로세스만 출력을 할 수 있습니다.

    #4

    $ ps -ef | grep python | wc -l

    위 #3을 응용해 python의 프로세스 갯수를 확인하려면 위와 같이 실행합니다.

    댓글