How to start jar package and run it in the background in Linux

How to start jar package and run it in the background in Linux

The Linux command to run the jar package is as follows:

Method 1:

java -jar shareniu.jar

Features: The current ssh window is locked. You can press CTRL + C to interrupt the program, or close the window directly to exit the program.

How to prevent the window from locking?

Method 2

java -jar shareniu.jar &

& represents running in the background.

Specific: The current ssh window is not locked, but when the window is closed, the program terminates.

Continue to improve, how to make the program still running when the window is closed?

Method 3

nohup java -jar shareniu.jar &

nohup means running the command without interruption. When the account is logged out or the terminal is closed, the program will still run.

When a job is executed with the nohup command, all output of the job is redirected to the nohup.out file by default unless an output file is specified otherwise.

Method 4

nohup java -jar shareniu.jar >temp.txt &

Explain>temp.txt

command >out.file

command >out.file redirects the output of command to the out.file file, that is, the output content is not printed on the screen, but output to the out.file file.

You can view background running tasks through the jobs command

jobs

Then all the background jobs will be listed, and each job will be preceded by a number.
If you want to call a job back to the foreground control, just use fg + the number.

fg 23

View the pid of the thread occupying a port

netstat -nlp |grep :9181

If you forget the process ID, you can use the following command to view the process ID of the currently running jar package program

ps -ef|grep xxx.jar

Or ps -aux | grep java

//Close the process

kill -s 9 24204

24204 represents the process ID found in the previous step

Summarize

The above is the implementation method of starting the jar package and running the jar package in the background in Linux introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Linux editing start, stop and restart springboot jar package script example
  • Shell script for one-click restart of Jar package and some experience sharing of new server deployment
  • Linux shell script to start jar package
  • The best way to start a jar package project under Centos7 server
  • Steps for automatic restart of jar package at startup under Windows

<<:  Vue achieves seamless carousel effect (marquee)

>>:  Solution to 1290 error when importing file data in mysql

Recommend

Detailed explanation of MySQL deadlock and database and table sharding issues

Record the problem points of MySQL production. Bu...

Several common CSS layouts (summary)

Summary This article will introduce the following...

The scroll bar position is retained when scrolling the vant list component

The scroll bar position is retained when scrollin...

Express implements login verification

This article example shares the specific code for...

MySQL exposes Riddle vulnerability that can cause username and password leakage

The Riddle vulnerability targeting MySQL versions...

Detailed explanation of the difference between var, let and const in JavaScript

Table of contents As a global variable Variable H...

Share the problem of Ubuntu 19 not being able to install docker source

According to major websites and personal habits, ...

Detailed explanation of the process of using GPU in Docker

Table of contents Download tf-gpu Build your own ...

Basic principles for compiling a website homepage

1. The organizational structure of the hypertext d...

A brief discussion on the efficiency of MySQL subquery union and in

Recent product testing found a problem that when ...

How to use fdisk to partition disk in Linux

Commonly used commands for Linux partitions: fdis...

Specific usage of CSS compound selectors

Intersection Selector The intersection selector i...

JavaScript implements mouse drag to adjust div size

This article shares the specific code of JavaScri...