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

Sitemesh tutorial - page decoration technology principles and applications

1. Basic Concepts 1. Sitemesh is a page decoratio...

CentOS8 network card configuration file

1. Introduction CentOS8 system update, the new ve...

Detailed steps for installing and configuring MySQL 8.0 on CentOS 7.4 64-bit

Step 1: Get the MySQL YUM source Go to the MySQL ...

A question about border-radius value setting

Problem Record Today I was going to complete a sm...

MySQL tutorial thoroughly understands stored procedures

Table of contents 1. Concepts related to stored p...

How to create a MySQL database (de1) using commands

1. Connect to MYSQL Format: mysql -h host address...

Display flex arrangement in CSS (layout tool)

Regarding display: flex layout, some people have ...

Explanation of the new feature of Hadoop 2.X, the recycle bin function

By turning on the Recycle Bin function, you can r...

Detailed explanation of the concept of docker container layers

Table of contents 01 Container consistency 02 Con...

Detailed explanation of docker-machine usage

Docker-machine is a Docker management tool offici...

Sample code for generating QR code using js

Some time ago, the project needed to develop the ...

A complete record of a Mysql deadlock troubleshooting process

Preface The database deadlocks I encountered befo...

MySQL InnoDB transaction lock source code analysis

Table of contents 1. Lock and Latch 2. Repeatable...