进程管理
ps命令
查看所有进程:ps -efl
查看指定参数:ps -eo pid,ppid,pgid,sid
查看CPU占用最高的进程:
ps -eo pid,pcpu k pcpu | tail -1
ps -eo pid,pcpu --sort pcpu | tail -1
ps -eo pid,pcpu | sort -nk 2 | tail -2
k和--sort一样,tail -1和tail -n 1一样。
sort:-n按字符串排序,-k 2表示根据输入的第2项排序(即pcpu)
查看CPU占用最高的线程:
ps H -eo pid,tid,%cpu k pcpu | tail -1
top命令
第一行
当前时间,系统运行了2天13小时25分,用户数,过去1,5,15分钟的系统负载
第二行
任务或线程统计,按H切换显示线程或者任务
第三行
第四行和第五行
按大写E切换内存显示单位(MB,KB等)
第四行是物理内存,第五行是虚拟内存
第六行
PID | 进程ID |
---|---|
USER | 用户名 |
PR | 优先级 |
NI | nice值,负值优先级高 |
VIRT | Virtual Memory Size (KiB) The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used. |
RES | Resident Memory Size (KiB) A subset of the virtual address space (VIRT) representing the non-swapped physical memory a task is currently using. It is also the sum of the RSan, RSfd and RSsh fields. |
SHR | Shared Memory Size (KiB) A subset of resident memory (RES) that may be used by other processes. It will include shared anonymous pages and shared file-backed pages. It also includes private pages mapped to files representing program images and shared libraries. |
S | 进程状态 D = uninterruptible sleep Tasks shown as running should be more properly thought of as ready to run -- their task_struct is simply represented on the Linux run-queue. Even without a true SMP machine, you may see numerous tasks in this state depending on top's delay interval and nice value. |
%CPU | The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if a process is multi-threaded and top is not operating in Threads mode, amounts greater than 100% may be reported. You toggle Threads mode with the `H' interactive command. Also for multi-processor environments, if Irix mode is Off, top will operate in Solaris mode where a task's cpu usage will be divided by the total number of CPUs. You toggle Irix/Solaris modes with the `I' interactive command. Note: When running in forest view mode (`V') with children collapsed (`v'), this field will also include the CPU time of those unseen children. See topic 4c. TASK AREA Commands, CONTENT for more information regarding the `V' and `v' toggles. |
%MEM | Memory Usage (RES) A task's currently resident share of available physical memory. |
TIME+ | CPU Time, hundredths The same as TIME, but reflecting more granularity through hundredths of a second. |
COMMAND | Command Name or Command Line Display the command line used to start a task or the name of the associated program. You toggle between command line and name with `c', which is both a command-line option and an interactive command. |