0

I'm running openjdk 1.8u191 on rather clean Ubuntu 16.04 and 18.04 systems, x86_64 hosts.

I run this simple application:

package net.iponweb;

import java.time.ZonedDateTime;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        while(true) {
            System.out.println(ZonedDateTime.now());
            Thread.sleep(1000);
        }
    }
}

with this command line:

java -jar sigalrm-1.0-SNAPSHOT.jar

Now when I send a SIGALRM signal to this java process by kill -14 ${PID}, I experience its immediate termination with the following output:

2019-03-07T18:36:13.150+03:00[Europe/Moscow]
2019-03-07T18:36:14.151+03:00[Europe/Moscow]
2019-03-07T18:36:15.152+03:00[Europe/Moscow]
Alarm clock

What bothers me is that I spent a couple hours trying to find any information regarding SIGALRM terminating JVM, but did not find any. My question is, is it an expected behavior, or an implementation-specific detail and the next stop for me is the JVM source code? Because I was not expecting SIGALRM to terminate my applications, and now I'm wandering if there's more.

iehrlich
  • 3,572
  • 4
  • 34
  • 43

1 Answers1

1

If you take a look at the man page for signal(7), you'll see this listing:

Signal      Standard   Action   Comment
----------------------------------------------------------
SIGALRM      P1990      Term    Timer signal from alarm(2)

Most signals' default actions are to terminate the process, either with or without a core dump. The most common way of handling signals in the JVM is to shut down cleanly when possible.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152