天天看點

根據程序名殺死程序 -kill -9 $(pidof 程序名關鍵字)

參考: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)

繼續閱讀