Linux下使用命令结束进程

来源:互联网 发布:日军退子弹 知乎 编辑:程序博客网 时间:2024/06/01 17:02

有时候某个软件卡死,想直接Kill掉。

1.ps -ef  或者 ps -aux 查看当前所有的进程:

xxxx:project/ $ ps -ef                                                                                                   [0:32:26]UID        PID  PPID  C STIME TTY          TIME CMDroot         1     0  0 Sep13 ?        00:00:00 /sbin/initroot         2     0  0 Sep13 ?        00:00:00 [kthreadd]root         3     2  0 Sep13 ?        00:00:00 [ksoftirqd/0]root         5     2  0 Sep13 ?        00:00:00 [kworker/0:0H]root         7     2  0 Sep13 ?        00:00:02 [rcu_sched]...... 

2. kill -s 9 process_id   (-s means signal ) 

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMANDroot         1  0.0  0.0  34032  4592 ?        Ss   Sep13   0:00 /sbin/init
PID is the processID


3. ps -ef或者ps -aux 两者列出来的进程都比较多,我们可以过滤。然后找到pid直接kill掉该进程。

xxxx:project/ $ ps -ef | grep firefox                                                                                    [0:39:56]xxxx   3027  1753  1 Sep13 ?        00:02:09 /usr/lib/firefox/firefoxxxxx  12604  9060  0 00:40 pts/1    00:00:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=.cvs --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn firefox

4. pgrep firefox       pgrep 是专门用于进程查询的

xxxx:project/ $ pgrep firefox                                                                                            [0:41:26]3027

如果这里能直接查出pid则,我们后面使用管道符号,直接干掉该进程

     1)pgrep firefox | xargs kill -s 9 

      或者

    2)kill -s 9 'grep firefox'

    或者

      3)pkill -9 firefox


5. 使用  pidof   查询

xxxx:project/ $ pidof firefox                                                                                            [0:43:01]3027

6.ps -ef|grep firefox|grep -v grep|cut -c 9-15|xargs kill -s 9 
xxxx:project/ $ ps -ef|grep firefox|grep -v grep|cut -c 9-15|xargs kill -s 9     


各种信号的含义:常见的有signal 11 / 9 / 6 / 3  android里面crash特别是系统级别的会常见。


Signal Description Signal number on Linux x86[1]SIGABRT Process aborted 6SIGALRM Signal raised by alarm 14SIGBUS Bus error: "access to undefined portion of memory object" 7SIGCHLD Child process terminated, stopped (or continued*) 17SIGCONT Continue if stopped 18SIGFPE Floating point exception: "erroneous arithmetic operation" 8SIGHUP Hangup 1SIGILL Illegal instruction 4SIGINT Interrupt 2SIGKILL Kill (terminate immediately) 9SIGPIPE Write to pipe with no one reading 13SIGQUIT Quit and dump core 3SIGSEGV Segmentation violation 11SIGSTOP Stop executing temporarily 19SIGTERM Termination (request to terminate) 15SIGTSTP Terminal stop signal 20SIGTTIN Background process attempting to read from tty ("in") 21SIGTTOU Background process attempting to write to tty ("out") 22SIGUSR1 User-defined 1 10SIGUSR2 User-defined 2 12SIGPOLL Pollable event 29SIGPROF Profiling timer expired 27SIGSYS Bad syscall 31SIGTRAP Trace/breakpoint trap 5SIGURG Urgent data available on socket 23SIGVTALRM Signal raised by timer counting virtual time: "virtual timer expired" 26SIGXCPU CPU time limit exceeded 24SIGXFSZ File size limit exceeded 25


BLOG REFERENCE: 

blog.csdn.net/andy572633/article/details/7211546


Linux config samba:

http://my.oschina.net/junn/blog/171388

0 0
原创粉丝点击