Raspberry Pi_Kor_19.1.1 시스템 상태 확인


Published Book on Amazon


All of IOT

Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1

All of IOT

Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사

물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)

최신 라즈베리파이(Raspberry Pi)로 시작하는 사

물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


19.1   CPU, Memory Task

 

CPU memory는 시스템이 가지고 있는 resource이고, 이들 resource를 사용하여 사용자가 지시한 작업을 하는 것이 task 또는 process 이다. 따라서 현재의 작업 처리상태에 문제가 없는지 확인하기 위해서는 시스템에서 가용한 resource와 현재 resource를 사용되고 있는 process에 대해서 모니터링하는 것이 필요하다

 

19.1.1  시스템 상태 확인

 

19.1.1.1    "top" 명령 - 시스템 주요 정보 확인

 

시스템의 전반적인 상태를 확인하고자 할 때 "top" 명령을 사용할 수 있다

 

[명령 형식]

top    [ options ]

 

[명령 개요]

    시스템에 대한 실시간 정보를 제공해 준다.

    user 권한    -- 일반 user.

 

[상세 설명]

    "top" 명령은 운영 시스템에 대한 실시간 정보를 제공해 준다. 여기서는 시스템 전체에 대한 요약 정보뿐만 아니라 Linux kernel이 관리하고 있는 개별 process thread에 대한 목록 자료를 함께 제공해 준다.

    여기서 제공되는 모든 정보들은 화면에서 제공하는 내부 명령행을 사용하여 사용자들이 원하는 방식으로 조정해서 조회할 수 있고, 이러한 조정 내역은 계속 저장되어 다음에 다시 사용할 수 있다.

    여기서 제공되는 정보는 정해진 간격으로 계속적으로 새로운 정보로 갱신하여 보여 준다.


 

[주요 option]

-h

Print help and then exit.

-b : Batch-mode operation

 

Starts top in 'Batch' mode, which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' Shell option or until killed.

-d : Delay-time interval as: -d ss.tt (secs.tenths)

Specifies the delay between screen updates, and overrides the corresponding value in one's personal configuration file or the startup default.  Later this can be changed with the 'd' or 's' interactive commands.

-H : Threads-mode operation

 

Instructs top to display individual threads.  Without this Shell option a summation of all threads in each process is shown. Later this can be changed with the 'H' interactive command.

-p : Monitor-PIDs mode as: -pN1 -pN2 ... or -pN1,N2,N3 ...

Monitor only processes with specified process IDs. This option can be given up to 20 times, or you can provide a comma delimited list with up to 20 pids. Co-mingling both approaches is permitted.

-u | -U : User-filter-mode as: -u | -U number or name

Display only processes with a user id or user name matching that given.  The '-u' option matches on effective user whereas the '-U' option matches on any user (real, effective, saved, or filesystem). The 'p', 'u' and 'U' Shell options are mutually exclusive.

 


 

[사용 Example]

다음은 "top" 명령을 실행한 결과 화면을 보여 준다.

 

pi@raspberrypi ~ $ top


그림 19‑1 시스템 모니터링 – "top" 명령

 

이 화면에서 제공되는 정보는 사용자가 특별한 지시를 하지 않아도, 시간이 지나면 화면이 새로운 내용으로 계속 갱신되는 것을 알 수 있다.

 

화면 위의 header 부분은 전체적인 summary 자료이고, 화면 아래의 목록 부분은 개별 process thread에 대한 상세정보를 보여주는 부분이다.

 

화면 header 영역과 list 영역 사이에 있는 부분이 내부 명령행이다. 여기서 필요한 명령을 내려서 화면에서 보이는 내용과 보이는 형태를 여러 가지로 조정해 볼 수 있다. 또한 필요하면 특정 process를 종료하기 위해서 kill 등의 작업을 할 수 있다.


 

다음은 header에 표시되는 정보 항목에 대한 설명이다

 

 

 

 

%CPU

us

사용자 application에 할당된 량

 

sy

시스템 application에 할당된 량

 

ni

nice process에 할당된 량

 

id

Idle

 

wa

I/O waiting process에 할당된 량

 

hi

hardware interrupt waiting process에 할당된 량

 

si

software interrupt waiting process에 할당된 량

 

st

hypervisor에 뺏긴 량

process 목록

PID

process id

 

PPID

parent process process id

 

Command

process에서 처리하는 명령 또는 프로그램

 

PR

process의 우선순위

 

VIRT

사용하는 가상메모리(virtual memory)의 양

 

RES

사용하고 있는 상주메모리(resident memory)의 양

 

SHR

사용하고 있는 공유메모리(shared memory)의 양

 

S

process 상태

 

TIME

Task 시작 이후 사용한 CPU 시간

 


 

사용할 수 있는 명령에 대한 상세한 자료가 필요하면 help 자료를 사용할 수 있다. "h"를 누르면 사용할 수 있는 전체 command 목록을 확인할 수 있다. 여기서 조정한 조회형태를 저장하여 다음에도 계속 사용하고자 하면 "w"를 눌러 설정 사항을 저장할 수 있다. 프로그램 실행을 종료하려면 "q"를 누른다.


 


 

19.1.1.2    "free" 명령 - memory 현황

 

"free" 명령은 시스템의 전체적인 memory 사용 상태에 대한 정보를 보여 준다

 

[명령 형식]

free    [ options ]

 

[명령 개요]

    시스템의 전체적인 memory 사용 상태를 보여준다.

    user 권한    -- 일반 user.

 

[상세 설명]

free 명령은 시스템에 있는 physical memory, swap memory, buffer/cache memory에 대해서 전체량, 사용량, 여유량을 요약해서 보여준다.

 

[주요 option]

--help

Print help.

-k, --kilo

Display the amount of memory in kilobytes.  This is the default.

-m, --mega

Display the amount of memory in megabytes

 

[사용 Example]

다음은 "free" 명령을 실행한 결과 화면이다.

 

pi@raspberrypi ~ $ free

             total       used       free     shared    buffers     cached

Mem:        380780     359936      20844          0      27560     187772

-/+ buffers/cache:     144604     236176

Swap:       102396          0     102396

 

 

 

 

 


 

19.1.1.3    "ps" 명령 - process snapshot

 

"ps" 명령은 현재 시스템에서 실행되고 있는 모든 process list 정보를 보여 준다.

 

[명령 형식]

ps    [ options ]

 

[명령 개요]

    현재 시스템에서 실행되고 있는 모든 process list 정보를 보여 준다

    user 권한    -- 일반 user.

 

[상세 설명]

option을 지정하지 않으면 현재 logon 사용자가 직접 실행한 process만 표시해 주고, background에서 실행되고 있는 process들은 제외한다.

 

[주요 option]

r

Restrict the selection to only running processes.

-N, --deselect

Select all processes except those that fulfill the specified conditions (negates the selection).   

-e

Select all processes.  Identical to -A.

-a

Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.

-C cmdlist

 

Select by command name.  This selects the processes whose executable name is given in cmdlist.

--pid pidlist

Select by process ID.  Identical to -p and p.

--ppid pidlist

Select by parent process ID.  This selects the processes with a parent process ID in pidlist.  That is, it selects processes that are children of those listed in pidlist.

-u userlist

 

Select by effective user ID (EUID) or name.  This selects the processes

whose effective user name or ID is in userlist. The effective user ID describes the user whose file access permissions are used by the process (see geteuid(2)).  Identical to U and --user.

-t ttylist

 

Select by tty.  This selects the processes associated with the terminals given in ttylist.  Terminals (ttys, or screens for text output) can be specified in several forms: /dev/ttyS1, ttyS1, S1.  A plain "-" may be used to select processes not attached to any terminal.

-f

Do full-format listing. This option can be combined with many other UNIX-style options to add additional columns. It also causes the command arguments to be printed.  When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added.  See the c option, the format keyword args, and the format keyword comm.

 

[사용 Example]

다음은 option을 지정하지 않고 "ps" 명령을 실행한 결과 화면이다. 현재 Terminal 화면에서 "ps" 명령을 실행하고 있는 상태이므로, "bash" "ps"만 목록에 표시되고 있다.

 

pi@raspberrypi ~ $ ps

  PID TTY          TIME CMD

 5752 pts/0    00:00:01 bash

 6135 pts/0    00:00:00 ps

 

다음은 선택조건을 "-a"로 지정하고 "f" option으로 process에 대한 정보를 full 방식으로 나타낸 것이다.   

 

pi@raspberrypi ~ $ ps -af

UID        PID  PPID  C STIME TTY          TIME CMD

pi        3481  3402  0 May28 tty1     00:00:01 -bash

pi        3507  3481  0 May28 tty1     00:00:00 /bin/sh /usr/bin/startx

pi        3524  3507  0 May28 tty1     00:00:00 xinit /etc/X11/xinit/xinitrc -- /etc/X11/xin

pi        3529  3524  0 May28 tty1     00:00:00 /usr/bin/ck-launch-session /usr/bin/dbus-lau

pi        3629  3529  0 May28 tty1     00:00:00 /usr/bin/lxsession -s LXDE-pi -e LXDE

pi        3632     1  0 May28 tty1     00:00:00 /usr/bin/dbus-launch --exit-with-session x-s

pi        3639  3629  0 May28 tty1     00:00:00 openbox --config-file /home/pi/.config/openb

pi        3641  3629  0 May28 tty1     00:03:54 lxpanel --profile LXDE-pi

pi        3648     1  0 May28 tty1     00:00:00 /usr/lib/arm-linux-gnueabihf/lxpolkit

pi        3672     1  0 May28 tty1     00:00:05 /usr/lib/arm-linux-gnueabihf/libmenu-cache1/

pi        5349  3629  0 09:11 tty1     00:00:01 pcmanfm --desktop --profile LXDE-pi

pi        6139  5752  0 13:42 pts/0    00:00:00 ps -af

 


 

아래는 결과 자료에서 나타나는 항목에 대한 설명이다

 

항목

설명

PID

process id

PPID

parent process process id

C

process CPU 사용량

STIME

process시작시간

TTY

process가 연결된 terminal

UID

user id

TIME

Task 시작 이후 사용한 CPU 시간

CMD

process를 실행한 명령과 argument

 

"ps" 명령으로 많은 process가 표시될 때 원하는 process만 선택하기 위해서 "grep" 명령을 사용하여 출력 자료중에서 원하는 자료만 선택할 수도 있다다음은 "ps" 명령으로 출력되는 전체 process 목록 중에서 <Motion> 프로그램에 관련된 process만 조회한 것이다

 

pi@raspberrypi ~ $ ps -ef | grep motion

motion    6835     1  1 19:07 ?        00:01:19 /usr/bin/motion

pi        7053  6586  0 20:16 pts/0    00:00:00 grep --color=auto motion


 

19.1.1.4    Desktop window를 통한 시스템 monitoring

 


Raspberry Pi
Desktop window로 접속한 경우에는 Desktop window 화면을 통하여 시스템을 모니터링할 수 있는 기능을 제공하는 Task Manager를 이용할 수 있다. Application MenuMenu àAccessories àTask Manager을 실행하면 아래와 같이 Task Manager 화면이 나타난다.

 

그림 19‑2 Desktop window Task Manager

 

이 프로그램은 시스템의 CPU memory 같은 리소스가 현재 어떤 상태에 있는지를 보여주며, 현재 실행되고 있는 여러 가지 Task에 대해 사용자가 원하는 유형의 task에 대한 정보를 보여 준다.

 

화면의 정보는 사용자가 특별한 지시를 하지 않아도, 시간이 경과하면 화면에 새로운 내용으로 계속 갱신되는 것을 알 수 있다. 갱신되는 시간 간격은 메뉴 View àPreferences에서 변경할 수 있다.

 

 


 

또한 아래 화면과 같이 상단의 메뉴 View를 이용하면 여러 가지 종류의 task를 선택적으로 조회할 수 있다.