Linux系统命令Top/free

Defunct processes are corrupted processes that can no longer communicate between the parent and child one. Sometimes, they become “zombies” and remain in your system until you reboot your machine. You can try to apply “kill -9″ command, but most of the time you’ll be out of luck.

In order to kill theses defunct processes, you have two choices:
1. Reboot your computer
2. Continue reading…

First, let’s find out if the system contains defunct process:

$ ps -A | grep defunct

Assume your output is as the following:

app      25883  0.0  0.0      0     0 ?        Z    Oct14   0:01 [ruby] <defunct>
app      30665  0.0  0.0      0     0 ?        Z    Oct15   0:01 [ruby] <defunct>

This means you have 2 of ruby. These processes exists because of poorly written application or unusual action taken by the user, in my case there must be some serious problem with the program I wrote in ruby

Now, let’s find the ID of the process and its parent’s:

$ ps -ef | grep defunct | more

The output from the above command:

UID       PID   PPID ...
---------------------------------------------------------------

app      20084 18156  0 19:09 pts/0    00:00:00 grep defunct
app      25883 27803  0 Oct14 ?        00:00:01 [ruby] <defunct>
app      30665 27803  0 Oct15 ?        00:00:01 [ruby] <defunct>

UID: User ID
PID: Process ID
PPID: Parent Process ID

If you try to kill the process with ID 20084 with the command “kill -920084 ″, it may not work. To properly kill it, you need to execute the kill command on its parent whose ID is 18156 ($kill -9 18156). Continue applying the kill command on all the PPID, and verify your result ($ps -A | grep defunct).

If the previous command display no result, well done, otherwise you may need to reboot your system.

Source:

http://wagoneers.com/UNIX/KILL/Kill.html

http://www.cts.wustl.edu/~allen/kill-defunct-process.html


On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table. This entry is still needed to allow the process that started the (now zombie) process to read its exit status. The term zombie process derives from the common definition of zombie—an undead person. In the term's colorful metaphor, the child process has died but has not yet been reaped. Also, unlike normal processes, the kill command has no effect on a zombie process.





1.作用

top命令用来显示执行中的程序进程,使用权限是所有用户。

2.格式

top [-] [d delay] [q] [c] [S] [s] [i] [n]

3.主要参数

d:指定更新的间隔,以秒计算。

q:没有任何延迟的更新。如果使用者有超级用户,则top命令将会以最高的优先序执行。

c:显示进程完整的路径与名称。

S:累积模式,会将己完成或消失的子行程的CPU时间累积起来。

s:安全模式。

i:不显示任何闲置(Idle)或无用(Zombie)的行程。

n:显示更新的次数,完成后将会退出top。

4.说明

top命令是Linux系统管理的一个主要命令,通过它可以获得许多信息。这里我们结合图1来说明它给出的信息。

top命令的显示 (图略)

第一行表示的项目依次为当前时间、系统运行时间、当前系统登录用户数目、1/5/10分钟系统平均负载(一般来说,这个负载值应该不太可能超过 1 才对,除非您的系统很忙碌。 如果持续高于 5 的话,那么.....仔细的看看到底是那个程序在影响整体系统吧!)。

第二行显示的是所有启动的进程、目前运行、挂起 (Sleeping)的和无用(Zombie)的进程。(比较需要注意的是最后的 zombie 那个数值,如果不是 0 ,嘿嘿!好好看看到底是那个 process 变成疆尸了吧?!)(stop模式:与sleep进程应区别,sleep会主动放弃cpu,而stop是被动放弃cpu ,例单步跟踪,stop(暂停)的进程是无法自己回到运行状态的)

第三行显示的是目前CPU的使用情况,包括us用户空间占用CPU百分比、sy 内核空间占用CPU百分比、ni 用户进程空间内改变过优先级的进程占用CPU百分比(中断处理占用)、id 空闲CPU百分比、wa 等待输入输出的CPU时间百分比、hi,si,st 三者的意思目录还不清楚 :)

第四行显示物理内存的使用情况,包括总的可以使用的内存、已用内存、空闲内存、缓冲区占用的内存。

第五行显示交换分区使用情况,包括总的交换分区、使用的、空闲的和用于高速缓存的大小。

第六行显示的项目最多,下面列出了详细解释。

PID(Process ID):进程标示号 ( 每个 process 的 ID )

USER:进程所有者的用户名 ( 该 process 所属的使用者 )

PR:进程的优先级别 ( Priority 的简写,程序的优先执行顺序,越小越早被执行 )

NI:进程的优先级别数值 ( Nice 的简写,与 Priority 有关,也是越小越早被执行 )

VIRT:进程占用的虚拟内存值。

RES:进程占用的物理内存值。

SHR:进程使用的共享内存值。

S:进程的状态,其中S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值是负数。

%CPU:该进程占用的CPU使用率。

%MEM:该进程占用的物理内存和总内存的百分比。

TIME+:该进程启动后占用的总的CPU时间 ( CPU 使用时间的累加 )

Command:进程启动的启动命令名称,如果这一行显示不下,进程会有一个完整的命令行。

top命令使用过程中,还可以使用一些交互的命令来完成其它参数的功能。这些命令是通过快捷键启动的。

<空格>:立刻刷新。

P:根据CPU使用大小进行排序。

T:根据时间、累计时间排序。

q:退出top命令。

m:切换显示内存信息。

t:切换显示进程和CPU状态信息。

c:切换显示命令名称和完整命令行。

M:根据使用内存大小进行排序。

W:将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。

可以看到,top命令是一个功能十分强大的监控系统的工具,对于系统管理员而言尤其重要。但是,它的缺点是会消耗很多系统资源。

5.应用实例

使用top命令可以监视指定用户,缺省情况是监视所有用户的进程。如果想查看指定用户的情况,在终端中按“U”键,然后输入用户名,系统就会切换为指定用户的进程运行界面,见图2所示。

a.作用

free命令用来显示内存的使用情况,使用权限是所有用户。

b.格式

free [-b|-k|-m] [-o] [-s delay] [-t] [-V]

c.主要参数

-b -k -m:分别以字节(KB、MB)为单位显示内存使用情况。

-s delay:显示每隔多少秒数来显示一次内存使用情况。

-t:显示内存总和列。

-o:不显示缓冲区调节列。

d.应用实例

free命令是用来查看内存使用情况的主要命令。和top命令相比,它的优点是使用简单,并且只占用很少的系统资源。通过-S参数可以使用free命令不间断地监视有多少内存在使用,这样可以把它当作一个方便实时监控器。

#free -b -s5

使用这个命令后终端会连续不断地报告内存使用情况(以字节为单位),每5秒更新一次。

(责任编辑:云子)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值