linux 进程命令

        Linux  系统主要有三种不同类型的进程,一般分为:

        交互进程:由一个终端(Shell)启动的进程,它既可以在前台运行,也可以在后台进行。

        批处理进程:和终端没有联系,是一个由脚本启动的进程序列。

        守护进程:在系统启动时通过脚本自动启动,或由root启动,通常在后台运行,直到系统关闭时退出。

1、ps命令

       ps可以在linux下面Shell终端中查看哪些进程正在运行,运行的状态,进程是否结束,进程有没有堵塞,那些进程占用了过多的资源。

       ps常用命令:

       ps  aux :以BSD风格显示进程

       

       ps alx:另外一种常用输出格式

         

ps输出字段含义
字段名含义
USER进程所有者
PID进程ID
PPID父进程
%CPUCPU占用率
TTY终端ID
%MEM内存占用率
NI进程优先级
VSN进程虚拟大小
RSS页面文件占用大小
STAT进程状态

ps命令进程状态标志符的含义
标志符含义
D不可以中断
S处于休眠状态
s包含子进程
T停止或被追踪
Z僵尸进程
+位于后台的进程组
R正在运行或队列中的进程
l (英文字母 l )多线程,克隆线程
X死掉的进程
<高优先级
N低优先级
L有些页被所进内存



2、kill命令

       kill  [-信号代码]<进程PID>

       kill命令用于向PID对应的进程发送信号代码所代表的信号,默认信号是-15,终止信号。使用这个命令需要有管理员权限。


3、pkill命令

      pkill  [-信号代码] [-u 用户名] [-t 终端号] [进程名]

      pkill命令是kill命令的批处理版,不同于kill命令的是,它无须制定的进程号,只需要指定进程名,就能批处理与指定进程名相同的进程。


4、top命令

       

     top [-] [d] [p] [q] [c] [C] [S]    [n]

    参数说明:

    d:  指定每两次屏幕信息刷新之间的时间间隔。当然用户可以使用s交互命令来改变之。

    p:  通过指定监控进程ID来仅仅监控某个进程的状态。

    q:该选项将使top没有任何延迟的进行刷新。如果调用程序有超级用户权限,那么top将以尽可能高的优先级运行。

    S: 指定累计模式

    s : 使top命令在安全模式中运行。这将去除交互命令所带来的潜在危险。

    i:  使top不显示任何闲置或者僵死进程。

    c:  显示整个命令行而不只是显示命令名


       top命令和ps命令的基本作用相同,但是,top是动态的,它可以通过用户不同的按键不停地刷新当前状态。

       这里偷一下懒,英文看起来舒服点。

a: PID  --  Process Id

       The task's unique process ID, which periodically wraps, though never  restarting at zero.

b: PPID  --  Parent Process Pid

       The process ID of a task's parent.

c: RUSER  --  Real User Name

       The real user name of the task's owner.

d: UID  --  User Id

       The effective user ID of the task's owner.

e: USER  --  User Name

       The effective user name of the task's owner.

f: GROUP  --  Group Name

       The effective group name of the task's owner.

g: TTY  --  Controlling Tty

       The  name of the controlling terminal.  This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses  for  input  oroutput.   However,  a task need not be associated with a terminal, in which case you'll see '?' displayed.

h: PR  --  Priority

       The priority of the task.

i: NI  --  Nice value

       The nice value of the task.   A  negative  nice  value  means  higher  priority, whereas  a  positive nice value means lower priority.  Zero in this field simply means priority will not be adjusted in determining a task's dispatchability.

j: P  --  Last used CPU (SMP)

       A number representing the last used processor.  In a true SMP  environment  this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity  and  cause  more processes  to change CPUs more often (because of the extra demand for cpu time).

k: %CPU  --  CPU usage

       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 '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.

l: TIME  --  CPU Time

       Total CPU time the task has used since it started.  When  'Cumulative  mode'  is On,  each  process is listed with the cpu time that it and its dead children has used.  You toggle 'Cumulative mode' with 'S', which is a command-line option and an interactive command.  See the 'S' interactive command for additional information regarding this mode.

m: TIME+  --  CPU Time, hundredths

       The same as 'TIME', but reflecting more granularity through hundredths of a sec          ond.

n: %MEM  --  Memory usage (RES)

       A task's currently used share of available physical memory.

o: VIRT  --  Virtual Image (kb)

       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.  (Note:  you  can define  the STATSIZE=1 environment variable and the VIRT will be calculated from the /proc/#/state VmSize field.)

       VIRT = SWAP + RES.

p: SWAP  --  Swapped size (kb)

       The swapped out portion of a task's total virtual memory image.

q: RES  --  Resident size (kb)

       The non-swapped physical memory a task has used.

       RES = CODE + DATA.

r: CODE  --  Code size (kb)

       The amount of physical memory devoted to executable  code,  also  known  as  the'text resident set' size or TRS.

s: DATA  --  Data+Stack size (kb)

       The  amount of physical memory devoted to other than executable code, also known the 'data resident set' size or DRS.

t: SHR  --  Shared Mem size (kb)

       The amount of shared memory used by a task.   It  simply  reflects  memory  that could be potentially shared with other processes.

u: nFLT  --  Page Fault count

       The  number  of  major  page faults that have occurred for a task.  A page fault occurs when a process attempts to read from or write to a virtual page  that  is not  currently  present  in  its address space.  A major page fault is when disk access is involved in making that page available.

v: nDRT  --  Dirty Pages count

       The number of pages that have been modified since  they  were  last  written  to disk.   Dirty  pages  must  be written to disk before the corresponding physical memory location can be used for some other virtual page.

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

       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.

x: Command  --  Command line or Program name

       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. When  you've  chosen  to display command lines, processes without a command line (like kernel threads) will be shown with only the program name  in  parentheses, as in this example:                ( mdrecoveryd ) Either  form  of  display is subject to potential truncation if it's too long to fit in this field's  current  width.   That  width  depends  upon  other  fields  selected, their order and the current screen width.

       Note: The 'Command' field/column is unique, in that it is not fixed-width.  When displayed, this column will be allocated all remaining screen width (up  to  the maximum  512  characters)  to  provide for the potential growth of program names into command lines.

y: WCHAN  --  Sleeping in Function

       Depending on the availability of the kernel link map ('System.map'), this  field will  show  the  name or the address of the kernel function in which the task is currently sleeping.  Running tasks will display a dash ('-') in this column.

       Note: By displaying this field, top's own working set will be increased by  over 700Kb.   Your  only  means of reducing that overhead will be to stop and restart          top.

z: Flags  --  Task Flags

       This column represents the task's current scheduling flags which  are  expressed in  hexadecimal  notation and with zeros suppressed.  These flags are officially documented in <linux/sched.h>.  Less formal documentation can also be  found  on the 'Fields select' and 'Order fields' screens.

        当你处于top命令下的时候,下面按键可以给你交互:

        h或者?  : 显示帮助画面,给出一些简短的命令总结说明。

        k:终止一个进程。系统将提示用户输入需要终止的进程PID,以及需要发送给该进程什么样的信号。一般的终止进程可以使用15信号;如果不                能正常结束那就使用信号9强制结束该进程。默认值是信号15。在安全模式中此命令被屏蔽。

        i:忽略闲置和僵死进程。这是一个开关式命令。

        q:退出程序。

        r: 重新安排一个进程的优先级别。系统提示用户输入需要改变的进程PID以及需要设置的进程优先级值。输入一个正值将使优先级降低,反之               则可以使该进程拥有更高的优先权。默认值是10。

        S:切换到累计模式。

        s :  改变两次刷新之间的延迟时间。系统将提示用户输入新的时间,单位为s。如果有小数,就换算成ms。输入0值则系统将不断刷新,默认值               是5 s。需要注意的是如果设置太小的时间,很可能会引起不断刷新,从而根本来不及看清显示的情况,而且系统负载也会大大增加。

        f或者F :从当前显示中添加或者删除项目。

        o或者O  :改变显示项目的顺序。

        l: 切换显示平均负载和启动时间信息。即显示影藏第一行

        m: 切换显示内存信息。即显示影藏内存行

        t : 切换显示进程和CPU状态信息。即显示影藏CPU行

        c:  切换显示命令名称和完整命令行。 显示完整的命令。 这个功能很有用。

        M : 根据驻留内存大小进行排序。

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

        T: 根据时间/累计时间进行排序。

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

5、特殊命令执行符

      Ctrl+Z组合键用于挂起当前Shell任务

      Ctrl+C组合键用于终止当前Shell任务

      Ctrl+D组合键用于输入完成或注销

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值