How can I stop all processes in IntelliJ?
Asked Answered
B

5

19

I am using intelliJ IDEA.

When I run my programs and close the window, the process still remains. If I run a lot of programs, I need to click disconnect many times.

Is there any way to stop all processes?

Eclipse doesn't have this problem.

PNG1

PNG2

Bridget answered 25/3, 2016 at 2:0 Comment(1)
Is the "setDefaultCloseOperation()" present in the Swing applications?Frigid
A
11

IntelliJ 2017.2 now has a "Stop All" button in the "Stop process" menu (the button on the top bar), with the default shortcut +F2 on Mac OS:

screenshot

For older versions:

  1. Click the Stop button from the top bar. It will pop open a menu listing all processes. (The stop button at the side of the debug window is per-process, as in your screenshot.)

  2. Hover over the first process, hold Shift, and then click on the last process.

  3. Press Enter.

Screenshot showing the result of steps 1 & 2:

screenshot

Acescent answered 12/6, 2017 at 20:10 Comment(4)
Command F2 is "Stop" not "Stop All" - at least on 2018.2 on macOS. I have many many bg processes that should die but do not.Superheterodyne
For background processes, the default shortcut is Shift+⌘+F2.Acescent
This isn't working for "zombie" processes which were started by IntelliJ but not cancelled.Cymric
@Cymric That's unfortunate -- sounds like a bug you should report to JetBrains!Acescent
C
8
kill $(ps aux | grep 'java' | awk '{print $2}')

This is a nice little workaround I found on SO a while ago that will kill any process with "java" in the name.

Just copy and paste into the terminal.

Cimabue answered 25/3, 2016 at 4:9 Comment(6)
I usually get the complain kill: kill (some number) failed: no such process but even when I get that, the processes still stopCimabue
when i paste it,i get kill is command or external command, Not recognized as operable program or batch file.Bridget
@Bridget try inputting that command into Cygwin if you're using Windows.Overword
nice solution, but running kill $(ps aux | grep 'java' | awk '{print $2}') as an external tool in intellij results in permission errors.Sacrificial
works as an 'external tool' if you put it is a bash file, and chmod a+x the bash file.Sacrificial
Simpler: pkill java (or pkill '.*java.*' to match this "contains" behavior).Acescent
R
2

Not exactly perfect, but what you could do is press Ctrl + F2 (shortcut for Stop Process) and hit Enter. It's better than all that mouse clicking and gets you through a list of running processes quite fast.

Readership answered 25/5, 2017 at 14:6 Comment(0)
M
2

You can create a script like killJavaProcess and invoke it in Before launch section as External tool

Before launch section

For example ~/.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 "$@"
Megaphone answered 17/3, 2021 at 21:8 Comment(0)
P
0

My environment is Windows, and I am using IntelliJ version 2024.1.2 (Community Edition). IntelliJ often shows that the port is blocked by another application when I restart my Spring Boot application. I resolved this problem by using a shell script to kill the process that occupies the port and adding it to the 'Add Before Launch Task' section of the run configuration.

IntelliJ Add Before Launch Task

enter image description here

kill_port_8081.bat:

@echo off
rem Check the port 8081 and kill the process using it

echo Looking for process using port 8081...
for /f "tokens=5" %%a in ('netstat -aon ^| findstr 8081') do (
    echo Process found using port 8081: PID %%a
    echo Killing process %%a...
    taskkill /F /PID %%a
    echo Process %%a killed.
)

echo Done.
pause
Peterman answered 26/7, 2024 at 8:50 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.