강좌 & 팁
전 터미널 작업을 많이 하다보니 ps 명령을 자주 사용합니다.
자꾸 잊어 먹기도 하고 무슨 옵션이 있나 찾아 보다가
ps 로도 상당히 많은 정보를 볼수 있길래 몇자 적어 봅니다.
디폴트로 사용하는 것
falinux@nadia:~$ ps -ely
S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD
S 0 1 0 0 80 0 1432 622 poll_s ? 00:00:01 init
S 0 2 0 0 80 0 0 0 kthrea ? 00:00:00 kthreadd
S 0 3 2 0 80 0 0 0 smpboo ? 00:00:01 ksoftirqd/0
S 0 5 2 0 60 -20 0 0 worker ? 00:00:00 kworker/0:0H
S 0 7 2 0 -40 - 0 0 smpboo ? 00:00:00 migration/0
S 0 8 2 0 80 0 0 0 rcu_gp ? 00:00:00 rcu_bh
S 0 9 2 0 80 0 0 0 rcu_gp ? 00:00:00 rcu_sched
S 0 10 2 0 -40 - 0 0 smpboo ? 00:00:00 migration/1
S 0 11 2 0 80 0 0 0 smpboo ? 00:00:00 ksoftirqd/1
프로세스 트리 보기
falinux@nadia:~$ ps axjf
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
0 2 0 0 ? -1 S 0 0:00 [kthreadd]
2 3 0 0 ? -1 S 0 0:01 \_ [ksoftirqd/0]
2 5 0 0 ? -1 S< 0 0:00 \_ [kworker/0:0H]
2 7 0 0 ? -1 S 0 0:00 \_ [migration/0]
2 8 0 0 ? -1 S 0 0:00 \_ [rcu_bh]
2 9 0 0 ? -1 S 0 0:00 \_ [rcu_sched]
2 10 0 0 ? -1 S 0 0:00 \_ [migration/1]
2 11 0 0 ? -1 S 0 0:00 \_ [ksoftirqd/1]
2 12 0 0 ? -1 S 0 0:00 \_ [kworker/1:0]
1 545 545 545 ? 10174 Ss 0 0:00 /bin/login --
545 586 586 545 ttymxc0 10174 S 1000 0:00 \_ -bash
586 10174 10174 545 ttymxc0 10174 R+ 1000 0:00 \_ ps axjf
레지스터 보기
falinux@nadia:~$ ps -A X
PID STACKP ESP EIP TMOUT ALARM STAT TTY TIME COMMAND
1 00000000 00000000 00000000 - - Ss ? 0:01 /sbin/init
2 00000000 00000000 00000000 - - S ? 0:00 [kthreadd]
3 00000000 00000000 00000000 - - S ? 0:01 [ksoftirqd/0]
5 00000000 00000000 00000000 - - S< ? 0:00 [kworker/0:0H]
7 00000000 00000000 00000000 - - S ? 0:00 [migration/0]
8 00000000 00000000 00000000 - - S ? 0:00 [rcu_bh]
9 00000000 00000000 00000000 - - S ? 0:00 [rcu_sched]
586 7e8b8e40 7e8b8938 76e49276 - - S ttymxc0 0:00 -bash
9212 00000000 00000000 00000000 - - S ? 0:00 [kworker/0:1]
9824 00000000 00000000 00000000 - - S ? 0:00 [kworker/0:0]
10314 00000000 00000000 00000000 - - S ? 0:00 [kworker/0:2]
10364 7e8bb890 7e8bb1c4 76e9e08c - - R+ ttymxc0 0:00 ps -A X
상태 파악
falinux@nadia:~$ ps ax
PID TTY STAT TIME COMMAND
1 ? Ss 0:01 /sbin/init
2 ? S 0:00 [kthreadd]
5 ? S< 0:00 [kworker/0:0H]
171 ? Ss 0:00 /sbin/udevd --daemon
178 ? Sl 0:00 rsyslogd -c5
263 ? S 0:00 /sbin/udevd --daemon
265 ? S 0:00 /sbin/udevd --daemon
465 tty4 Ss+ 0:00 /sbin/getty -8 38400 tty4
500 ? SNs 0:13 /usr/sbin/preload -s /var/lib/preload/preload.state
10809 ttymxc0 R+ 0:00 ps ax
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)
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped, either by a job control signal or because it is being traced.
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.
Ss : 인터럽터블 슬립 / 세션 리더
S : 인터럽터블 슬립
S< : 인터럽터블 슬립 / 높은 우선순위 가짐... nice 하지 않아요~
Sl : 인터럽터블 슬립 / 멀티 쓰레드
Ss+ : 인터럽터블 슬립 / 세션 리더 / 포그라운드(실행중인) 프로세스 그룹
SNs : 인터럽터블 슬립 / 낮은 우선순 / 세션 리더위
이 정도의 정보가 되겠네요.
생각보다 재밌군요.
추가팁...
프로세스의 address space 를 보고플때
falinux@nadia:~$ sudo cat /proc/11341/maps
00008000-0000f000 r-xp 00000000 08:01 6553696 /bin/ping
00016000-00017000 r--p 00006000 08:01 6553696 /bin/ping
00017000-00018000 rw-p 00007000 08:01 6553696 /bin/ping
00018000-0002b000 rw-p 00000000 00:00 0
0187e000-0189f000 rw-p 00000000 00:00 0 [heap]
76e8b000-76e8c000 rw-p 00000000 00:00 0
76e8c000-76f62000 r-xp 00000000 08:01 2752654 /lib/arm-linux-gnueabihf/libc-2.15.so
76f62000-76f6a000 ---p 000d6000 08:01 2752654 /lib/arm-linux-gnueabihf/libc-2.15.so
76f6a000-76f6c000 r--p 000d6000 08:01 2752654 /lib/arm-linux-gnueabihf/libc-2.15.so
76f6c000-76f6d000 rw-p 000d8000 08:01 2752654 /lib/arm-linux-gnueabihf/libc-2.15.so
76f6d000-76f71000 rw-p 00000000 00:00 0
76f71000-76f79000 r-xp 00000000 08:01 2752778 /lib/arm-linux-gnueabihf/libgcc_s.so.1
76f79000-76f80000 ---p 00008000 08:01 2752778 /lib/arm-linux-gnueabihf/libgcc_s.so.1
76f80000-76f81000 r--p 00007000 08:01 2752778 /lib/arm-linux-gnueabihf/libgcc_s.so.1
76f81000-76f82000 rw-p 00008000 08:01 2752778 /lib/arm-linux-gnueabihf/libgcc_s.so.1
76f82000-76f99000 r-xp 00000000 08:01 2752682 /lib/arm-linux-gnueabihf/ld-2.15.so
76f9c000-76f9f000 rw-p 00000000 00:00 0
76f9f000-76fa0000 r-xp 00000000 00:00 0 [sigpage]
76fa0000-76fa1000 r--p 00016000 08:01 2752682 /lib/arm-linux-gnueabihf/ld-2.15.so
76fa1000-76fa2000 rw-p 00017000 08:01 2752682 /lib/arm-linux-gnueabihf/ld-2.15.so
7ef07000-7ef28000 rw-p 00000000 00:00 0 [stack]
ffff0000-ffff1000 r-xp 00000000 00:00 0 [vectors]
커널 공간을 제외한 유저공간에서 볼수 있는 맵을 볼수 있습니다.
올해에는 배쉬와 스크립트를 더 많이 할듯 한 예감이네요.