参考:https://blog.csdn.net/zhaoyue007101/article/details/7699259
#kill -9 $(ps -ef|grep 进程名关键字|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ')
在开发平台上ps -ef不支持,执行项只有
# ps -ef
ps: invalid option -- 'e'
BusyBox v1.23.2 (2016-11-15 23:14:33 CST) multi-call binary.
Usage: ps
Show list of processes
w Wide output
l Long output
T Show threads
修改字段:
ps -l | grep jarves | awk '$0 !~/grep/ {print $2}' |tr -s '\n' ' '
ps -l | grep jarves
S 0 7414 520 3576 400 ttyS0 01:31 00:00:00 grep jarves
# ps -w | grep jarves
779 root 250m S {MSystem::Run} /applications/bin/jarves
9367 root 3576 S grep jarves
# ps -w | grep jarves | awk '$0 !~/grep/ {print $1}'
779
然后可以用:
kill -9 $(ps -w | grep jarves | awk '$0 !~/grep/ {print $1}')
这个是利用管道和替换将 进程名对应的进程号提出来作为kill的参数。很显然上面的方法能完成但是过于复杂,
下面这种就显得简单的多了
2、#kill -9 $(pidof 进程名关键字)
kill -9 $(pidof jarves)
附录:
linux signals
Signal Name | Number | Description |
SIGHUP | 1 | Hangup (POSIX) |
SIGINT | 2 | Terminal interrupt (ANSI) |
SIGQUIT | 3 | Terminal quit (POSIX) |
SIGILL | 4 | Illegal instruction (ANSI) |
SIGTRAP | 5 | Trace trap (POSIX) |
SIGIOT | 6 | IOT Trap (4.2 BSD) |
SIGBUS | 7 | BUS error (4.2 BSD) |
SIGFPE | 8 | Floating point exception (ANSI) |
SIGKILL | 9 | Kill(can't be caught or ignored) (POSIX) |
SIGUSR1 | 10 | User defined signal 1 (POSIX) |
SIGSEGV | 11 | Invalid memory segment access (ANSI) |
SIGUSR2 | 12 | User defined signal 2 (POSIX) |
SIGPIPE | 13 | Write on a pipe with no reader, Broken pipe (POSIX) |
SIGALRM | 14 | Alarm clock (POSIX) |
SIGTERM | 15 | Termination (ANSI) |
SIGSTKFLT | 16 | Stack fault |
SIGCHLD | 17 | Child process has stopped or exited, changed (POSIX) |
SIGCONT | 18 | Continue executing, if stopped (POSIX) |
SIGSTOP | 19 | Stop executing(can't be caught or ignored) (POSIX) |
SIGTSTP | 20 | Terminal stop signal (POSIX) |
SIGTTIN | 21 | Background process trying to read, from TTY (POSIX) |
SIGTTOU | 22 | Background process trying to write, to TTY (POSIX) |
SIGURG | 23 | Urgent condition on socket (4.2 BSD) |
SIGXCPU | 24 | CPU limit exceeded (4.2 BSD) |
SIGXFSZ | 25 | File size limit exceeded (4.2 BSD) |
SIGVTALRM | 26 | Virtual alarm clock (4.2 BSD) |
SIGPROF | 27 | Profiling alarm clock (4.2 BSD) |
SIGWINCH | 28 | Window size change (4.3 BSD, Sun) |
SIGIO | 29 | I/O now possible (4.2 BSD) |
SIGPWR | 30 | Power failure restart (System V) |