Wednesday, March 7, 2018

How to Start a jar as background process | nohup Command

To Start a jar as background process
 In case we want to start a service using a java jar, without associating it to current terminal command is:-


nohup java -jar user-demo.jar  &
nohup will start the jar as background process.  

nohup java -jar user-demo.jar  & > output.txt
output of process will be written to output.txt in current directory where command was executed.

Directly starting the jar with java -jar command will attach the process to the current terminal. As soon you log out from the terminal or get disconnected from the window, the process will be killed. If you are deploying a jar on the remote server, you need to start it as a background process.

Using '&' will return you immediately to current terminal and will print the process id number.

Prefixing any command with nohup prevents the command from being terminated when you exit the shell.




No comments:

Post a Comment