본문 바로가기

DevOps/[Linux]

[인프라 기초] CentOS 실습해보기 -3 (프로세스 관리)

반응형

상태 코드

 

리눅스의 프로세스들의 상태를 확인할 수 있는 코드들이 있다.

 

man ps 명령어를 입력하면, ps에 대한 매뉴얼이 나온다.

 

페이지를 내려보다보면, State Code에 대한 설명이 나와있다.

 

 

PROCESS STATE CODES
       Here are the different values that the s, stat and state output
       specifiers (header "STAT" or "S") will display to describe the state of
       a process:

               D    uninterruptible sleep (usually IO)
               I    Idle kernel thread
               R    running or runnable (on run queue)
               S    interruptible sleep (waiting for an event to complete)
               T    stopped by job control signal
               t    stopped by debugger during the tracing
               W    paging (not valid since the 2.6.xx kernel)
               X    dead (should never be seen)
               Z    defunct ("zombie") process, terminated but not reaped by
                    its parent

       For BSD formats and when the stat keyword is used, additional
       characters may be displayed:
               <    high-priority (not nice to other users)
               N    low-priority (nice to other users)
               L    has pages locked into memory (for real-time and custom IO)
               s    is a session leader
               l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads
                    do)
               +    is in the foreground process group

 

State Code

의미

D

중간에 인터럽트를 걸 수 없는 Sleep상태.(일반적으로 IO(장치와의 입출력))

I

Idle 상태, 유휴상태

R

수행 중, 혹은 수행 가능한 상태

S

위의 D와는 다르게, 인터럽트가 가능한 Sleep상태

T

제어 신호에 의해 중지됨

t

Tarcking 디버거에 의해 중지됨

W

페이징

X

프로그램 죽음Dead

Z

Defunct 좀비프로세스, 종료되었지만 메모리 회수가 안 된 상태

 

ps명령어 : 현재 수행중인 프로세스에 대한 정보들을 출력한다.

옵션 :

-e : 모든 정보 출력

-f : 자세한 정보 출력

-u uid: 특정 사용자(UserID) 에 대한 모든 프로세스 정보 출력

-p pid : pid로 지정한 특정 프로세스의 정보 출력

-l : state code가 포함된 정보 출력

 

 

여기서 ps -ef 를 해본다.

 

제일 위에 보이는 프로세스가 제일 먼저 실행된 프로세스이다.

대괄호로 싸여진 부분들이 Thread이다.

 

UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 08:49 ?        00:00:03 /usr/lib/systemd/systemd --switched
root           2       0  0 08:49 ?        00:00:00 [kthreadd]
root           3       2  0 08:49 ?        00:00:00 [rcu_gp]
root           4       2  0 08:49 ?        00:00:00 [rcu_par_gp]
root           6       2  0 08:49 ?        00:00:00 [kworker/0:0H-kblock

 

 

프로세스 종료

kill 이나 pkill 명령어로 프로세스 종료 가능

이 명령어들은 프로세스에 시그널을 보내서 종료함

 

시그널이란 프로세스에 무엇인가 발생했음을 알리는 메시지.

주요 시그널로는 SIGHUP, SIGINT, SIGQUIT, SIGKILL 등이 있다.

 

kill 명령 사용 방법 : kill -[시그널 번호] [프로세스ID] 

 

 

top명령어

ps명령어는 현재 수행중 프로세스들을 캡쳐해서 나타냈다면,

top명령은 실시간(3초마다 update)으로 프로세스들을 보여준다.

 

 

 

작업 예약

 

at : 예약한 명령을 정해진 시간에 실행한다.

at [옵션] [시간]

 

-l : 현재 실행 대기중인 명령의 전체 목록을 출력한다.

 

crontab 명령을 사용하면, 파일형식으로 작업을 예약할 수 있다.

 

 

 

반응형