JaskeyLam
JaskeyLam

Reputation: 15755

Java process does not terminate when sending kill signal

Sometimes, we will face that we try to kill a java process, but the process does not terminate, we have to send kill -9 to terminate it.

Questsion:

  1. When a java process receive a kill -15 signal, what will happens
  2. What is the possible reason if the process does not terminate, and how to diagnose?

Upvotes: 0

Views: 1663

Answers (2)

apangin
apangin

Reputation: 98284

When a Java process, or more precisely HotSpot JVM, receives signal 15 (SIGTERM), it initiates shutdown sequence. One of its essential steps is the invocation of Shutdown hooks.

Shutdown hooks are regular Java threads. By the convention, they should finish their work quickly, but sometimes (just like regular Java code) shutdown hooks may loop, block, wait for something or otherwise delay the termination. JVM will hang until all shutdown hooks complete.

Use jstack utility to find what prevents the timely termination. Look for SIGTERM handler thread in a thread dump - it will be probably waiting for some other (offender) thread to complete. JVM will not exit normally while the offender thread is running.

Upvotes: 2

FakeAlcohol
FakeAlcohol

Reputation: 990

  1. kill -15: Send SIGTERM, kill the process, but allow it to do some cleanup first. Peaceful terminating.

  2. Waiting for i/o and so on.

Upvotes: 1

Related Questions