[英]How can I stop all processes in IntelliJ?
我正在使用 IntelliJ IDEA。
當我運行我的程序並關閉窗口時,該過程仍然存在。 如果我運行很多程序,我需要多次單擊斷開連接。
有沒有辦法停止所有進程?
Eclipse 沒有這個問題。
kill $(ps aux | grep 'java' | awk '{print $2}')
這是我不久前在 SO 上發現的一個不錯的小解決方法,它會殺死任何名稱中帶有“java”的進程。
只需復制並粘貼到終端中。
不完全完美,但您可以按 Ctrl + F2(停止進程的快捷方式)並按 Enter。 它比所有的鼠標點擊都要好,它能讓你快速瀏覽正在運行的進程列表。
您可以創建一個像killJavaProcess
這樣的腳本,並Before launch
部分作為External tool
調用它
例如~/.bin/killonport
#!/bin/zsh
function help() {
echo "usage: killonport port"
echo "-f don't ask before killing"
echo "-h help"
}
function killListenerOnPort() {
# get script options
zparseopts -E -D h=HELP f=FORCE
[[ -n $HELP ]] &&
help &&
return
local PORT
PORT=$1
[[ -z "$PORT" ]] &&
help &&
return
local LISTEN
# find process listening on port with lsof
LISTEN="$(lsof -nP -iTCP:"$PORT" -sTCP:LISTEN)"
local PROCESS
# remove first line of output lsof
PROCESS="$(echo "$LISTEN" | tail -n +2)"
local HEAD
# get first line of output lsof
HEAD="$(echo "$LISTEN" | head -n 1)"
[[ -z $PROCESS ]] &&
echo "Process not found" &&
return
local COUNT
# assure that found only one process else printing founded processes and exit
COUNT=$(echo "$PROCESS" | wc -l | xargs)
[[ $COUNT -gt 1 ]] &&
printf 'Found more then one process: %s\n%s\n%s\n' "$COUNT" "$HEAD" "$PROCESS" &&
return
# get name and PID
local NAME
NAME=$(echo "$PROCESS" | awk '{print $1}')
local PID
PID=$(echo "$PROCESS" | awk '{print $2}')
# if -f option specified kill silently
[[ -n "$FORCE" ]] &&
kill -9 "$PID" &&
return
# ask confirmation to kill
echo "Kill process '$NAME' with PID '$PID'"
read -qr 'REPL?Continue? (y/n) '
echo
# kill if confirmed
[[ $REPL == 'y' || $REPL == 'Y' ]] &&
kill -9 "$PID"
}
killListenerOnPort "$@"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.