47

When I close a java program in intellJ, the following log appears in the console: "Process finished with exit code 130"

screenshot of java program exit code

Some times, the code is "1".

I know this is the very basic, but I googled Internet and still couldn't find the explanation for the exit code.

What does the code mean? Where can I find the explanation?

3
  • 14
    tldp.org/LDP/abs/html/exitcodes.html Commented Apr 27, 2015 at 4:17
  • 2
    ahh.. so it is bash code, not code in Java program. Thanks! Commented Apr 27, 2015 at 4:26
  • 3
    If you hit Ctrl+R to rerun the program or forcibly close the program, it's also a exit code 130, it doesn't have to be initialized by Ctrl+C, it's just a OS wide signal code to indicate that the current process has received an Terminated signal. Commented Apr 24, 2019 at 22:14

3 Answers 3

67

To steal @Baby 's answer from the comments and formalize it, the 130 exit code is given by bash, and Mendel Cooper's Bash-Scripting Guide states that it indicates that the process was terminated by a SIGTERM. Generally this is the user pressing Ctrl-C.

Sign up to request clarification or add additional context in comments.

2 Comments

For me this happened in a docker container when I did docker logs <containerID>. Somehow doing ^C on docker logs killed the container!
I think, the comment from @cst1992 is now fixed. I tried docker logs, docker logs --follow and docker attach. Only the last killed the process that was running. I even tried an endless loop, because docker logs terminates else
7

This answer is applicable if you want to get the behavior of many native apps that return code 0 after a graceful shutdown.

You can register a hook that performs the graceful shutdown, for example releasing resources retained by the app. If the graceful shutdown succeeds, this hook can also override the exit code to 0. The hook will be called on SIGTERM (happens when the user is pressing Ctrl+C).

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread(
                () -> {
                  //graceful shutdown steps
                  Runtime.getRuntime().halt(0); //override the exit code to 0
                }));

The solution above will prevent other hooks that may exist to run after this one. It will also prevent files to be deleted that had .deleteOnExit() called.

Another approach may be implementing and registering a SecurityManager that looks like this:

  static class Converting130To0SecurityManager extends SecurityManager {
    @Override
    public void checkExit(int status) {
      if (status == 130) {
        System.exit(0);
      } else {
        super.checkExit(status);
      }
    }

    @Override
    public void checkPermission(Permission perm) {
      // Allow all activities by default
    }
  }

  ...
  System.setSecurityManager(new Converting130To0SecurityManager());

Such a security manager will always transform 130 code into 0 irrespectively of the graceful shutdown.

Comments

0

You can simply ignore it, it means that the app accepted SIGINT.
Set the DEBUG log level, and it will explain it to you, you will see something like this.

[ SIGINT handler] java.lang.RunTime : Runtime.exit() called with status: 130

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.