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

Three principles of efficient navigation design that web designers must know

Designing navigation for a website is like laying...

Vue3 list interface data display details

Table of contents 1. List interface display examp...

Completely uninstall MySQL database in Windows system to reinstall MySQL

1. In the control panel, uninstall all components...

SQL implementation of LeetCode (196. Delete duplicate mailboxes)

[LeetCode] 196.Delete Duplicate Emails Write a SQ...

Beginners learn some HTML tags (1)

Beginners can learn HTML by understanding some HT...

Should the Like function use MySQL or Redis?

Table of contents 1. Common mistakes made by begi...

Solve the Docker x509 insecure registry problem

After installing Docker, I encountered the x509 p...

Vue+Vant implements the top search bar

This article example shares the specific code of ...

Looping methods and various traversal methods in js

Table of contents for loop While Loop do-while lo...

MySQL table field time setting default value

Application Scenario In the data table, the appli...

Implementation steps for installing Redis container in Docker

Table of contents Install Redis on Docker 1. Find...

Causes and solutions for slow MySQL queries

There are many reasons for slow query speed, the ...

The basic use of html includes links, style sheets, span and div, etc.

1. Links Hypertext links are very important in HTM...

CentOS7 firewall and port related commands introduction

Table of contents 1. Check the current status of ...

Detailed explanation of the new array methods in JavaScript es6

Table of contents 1. forEach() 2. arr.filter() 3....