Tải bản đầy đủ (.pdf) (6 trang)

Topic 3.3 Process Management

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (430.61 KB, 6 trang )

1. Theo dõi các tiến trình
Tạo user nv1, nv2

Quản lý tiến trình

ps -ax xem thơng tin tất cả các tiến trình

PID: process ID
PPID: Parent process ID
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
Alt+f2 login root


#ps -ef | more



xem tiến trình cha, con.

Ý nghĩa các cột
■ UID: The user responsible for launching the process
■ PID: The process ID of the process
■ PPID: The PID of the parent process (if a process is started by another process)
■ C: Processor utilization over the lifetime of the process
■ STIME: The system time when the process started
■ TTY: The terminal device from which the process was launched
■ TIME: The cumulative CPU time required to run the process
■ CMD: The name of the program that was started
xem thông tin các tiến trình theo cấu trúc cây:
pstree -np | more
[root@localhost ~]# pstree -np | more
init(1)-+-udevd(415)-+-udevd(1740)
|
`-udevd(1742)
|-auditd(1248)---{auditd}(1249)
|-rsyslogd(1264)-+-{rsyslogd}(1267)
|
`-{rsyslogd}(1268)
|-rpcbind(1306)
|-dbus-daemon(1321)---{dbus-daemon}(1324)
|-NetworkManager(1333)
|-modem-manager(1339)
|-avahi-daemon(1345)---avahi-daemon(1346)
|-rpc.statd(1363)
|-wpa_supplicant(1428)
|-rpc.idmapd(1429)

70

Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ


|-acpid(1443)
|-hald(1452)---hald-runner(1453)-+-hald-addon-inpu(1493)
|
`-hald-addon-acpi(1499)
Theo dõi tiền trình login của u1, u2
Alt+F2, login u1;
Alt+F3, login u3;

chạy mc
chạy mc

[root@localhost ~]# pstree -np | more

…………………………………………..
|-abrtd(1650)
|-abrt-dump-oops(1658)
|-qpidd(1669)-+-{qpidd}(1670)
|
`-{qpidd}(1671)
|-crond(1707)
|-atd(1718)
|-login(1731)---bash(2024)---pstree(2250)
|-login(1733)---bash(2057)---mc(2089)-+-cons.saver(2090)
|
`-bash(2091)

|-login(1735)---bash(2115)---mc(2227)-+-cons.saver(2228)
|
`-bash(2229)

Hoặc:
[root@localhost ~]# pstree -nup | more
ps -u u1

xem thơng tin tiến trình u1 khởi tạo
[root@localhost ~]# ps -u u1
PID TTY
TIME CMD
2057 tty2 00:00:00 bash
2089 tty2 00:00:00 mc
2090 ?
00:00:00 cons.saver
2091 pts/5 00:00:00 bash

Hủy tiến trình theo PID
kill PID
[root@localhost ~]# pkill 2089

# 2089 là PID của mc do u1 khởi rạo

Hủy tiến trình theo tên
pkill named hoặc
killall processes by name
[root@localhost ~]# pkill mc
Lệnh killall: được dùng khi muốn kill tất cả các process với tên chắc chắn. Lúc này khơng cần dùng
ps để tìm PID. Ví dụ: # killall httpd

[root@localhost ~]# pgrep sendmail
[root@localhost ~]# pkill sendmail
[root@localhost ~]# pgrep sendmail
khởi động lại sendmail
[root@localhost ~]# service sendmail start

#tìm pid của sendmail
#hủy tiến trình sendmail
#tìm pid của sendmail


2. Nhận dạng tiến trình
Tiến trình tiền cảnh: do user tạo ra và giao tiếp trực tiếp với user
vd: mc
Tiến trình hậu cảnh: (deamon process)
- do người dùng tạo ra
- do hệ thống tạo ra, nó tự động kích hoạt
Đưa 1 tiến trình vào hậu cảnh
- Chạy mc, nhấn Ctrl+Z
Hoặc thêm & vào sau câu lệnh
[root@localhost ~]# sleep 1000 &
[root@localhost ~]# sleep 1500 &
Xem các tiến trình trong hậu cảnh
[root@localhost ~]# jobs
[1]+ Stopped
mc
[2] Running
sleep 1000 &
[3]- Running
sleep 1500 &

Lệnh bg %n
Lệnh fg %n

: chạy tính trình trong hậu cảnh
: đưa tiến trình ra tiền cảnh

3. Theo dõi performance của hệ thống
Lệnh top
Key Switches For The Top Command:
-h - Show the current version
-c - This toggles the command column between showing command and program name
-d - Specify the delay time between refreshing the screen
-o - Sorts by the named field
-p - Only show processes with specified process IDs
-u - Show only processes by the specified user
-i - Do not show idle tasks

72

Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ


Xem thông số CPU:
us percent cpu being used by userland code
sy percent cpu being used by kernelspace code
ni like "us" but related to "niced" processes
id idle
wa cpu is idle because it waits for IO to complete
hi interrupts generated by hardware
si interrupts generated by software

Các trạng thái:
w: S -- Process Status
The status of the task which can be one of:
'D' = uninterruptible sleep
'R' = running
'S' = sleeping
'T' = traced or stopped
'Z' = zombie


Ý nghĩa các cột
PID: The process ID of the process
USER: The user name of the owner of the process
PR: The priority of the process
NI: The nice value of the process
VIRT: The total amount of virtual memory used by the process
RES: The amount of physical memory the process is using
SHR: The amount of memory the process is sharing with other processes
S: The process status (D = interruptible sleep, R = running, S = sleeping, T = traced or
stopped, or Z = zombie)
%CPU: The share of CPU time that the process is using
%MEM: The share of available physical memory the process is using
TIME+: The total CPU time the process has used since starting
COMMAND: The command line name of the process (program started)
Xuất kết quả lệnh top ra file:
top -cSb -n 1 > proc.txt
Có thể sử dụng tiện ích htop để xem và kiểm sốt các tiến trình

74


Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×