Linux进程管理(一)
Linux进程管理(一)
😄 Written by Zak Zhu
参考
- 马哥linux视频
- u013184884/利用pwdx查看Linux程序的工作目录(https://blog.csdn.net/u013184884/article/details/82993286)
- 菲宇/Linux进程内存分析pmap命令(https://blog.csdn.net/bbwangj/article/details/80698291)
- RHCE培训(RH033-Unit10)
pstree命令
pstree -p
pidof命令
根据服务名, 查找进程号
e.g. pidof named
Tips: pidof的命令退出码(
$?
)不为0时, 表示服务没有起来
pmap命令
pmap - report memory map of a process
pmap [OPTIONS] PID...
Options:
-x # show details
-d # show offset and device number
-
e.g.
pmap -d 1
- Address # start address of map
- Kbytes # size of map in kilobytes
- RSS # resident set size in kilobytes
- Dirty # dirty pages (both shared and private) in kilobytes
- Mode # permissions on map
- Mapping # file backing the map, or '[ anon ]' for allocated memory, or '[ stack ]' for the program stack
- Offset # offset into the file
- Device # device name
- mapped # Virtual memory set size
- writeable/private # Real used memory
- shared # Shared memory
-
e.g.
pmap -x 1
pwdx命令
在工作中, 我们经常会看到多个相似的进程同时运行. 有时候, 需要对其中一两个进程进行操作, 比如杀掉, 也会经常担心杀错.
pwdx命令, 利用进程号作为参数, 可以打印出指定进程号的工作目录, 帮助我们区分不同的进程
pwdx PID
ps命令
ps -efH
ps -eHo user,group,pid,ppid,stat,%cpu,psr,%mem,ni,cmd,time
Process State Codes:
man ps
- D # uninterruptible sleep (usually IO)
- R # running
- S # interruptible sleep (waiting for an event to complete)
- T # stopped by job control signal
- t # stopped by debugger during the tracing
- X # dead (should never be seen)
- Z # zombie process, terminated but not reaped by its parent
additional characters may be displayed:
- < # high-priority
- N # lower-priority
- L # has pages locked into memory (for real-time and custom IO)
- s # is a session leader
- l # is multi-threaded
- + # is in the foreground process group
nice调优
Scheduling priority determines access to the CPU
Priority is affected by a process' nice value
Values range from -20 to 19 but default to 0
Lower nice value means higher CPU priority
Nice value may be altered ...
-
When starting a process:
e.g.
nice -n 5 COMMAND
-
Afer starting:
e.g.
renice -n 5 PID
发送信号
Signal | Value | Comment |
---|---|---|
SIGHUP | 1 | 让程序重读配置文件, 而不用重启程序 |
SIGINT | 2 | 中断信号(Ctrl + C即发送该信号) |
SIGKILL | 9 | 暴力杀死进程 |
SIGTERM | 15 | 温柔终止进程(默认) |
-
By PID
kill -SIGNAL PID
-
By Pattern
pkill -SIGNAL PATTERN