Search code examples
linuxubuntujarbackground-process

Linux command run cpp and jar


I'm new with Linux environment, so sorry for the question.

I have a real time REST API with an app client (Java) and server (C++). I have a Ubuntu machine.

I know that to run C++ it is:

$ ./nameOfProgram &

and for the Java is:

$ java -jar file.jar &

The & to allow me to continue use the command shell of Linux while my programs are running.

I access to the Ubuntu machine with ssh (with putty) but if I close the connection my programs stop.

What is the best way to always put my programs running in the background even if it is not connected to the machine. My programs are Java and C++, they are in different folders.


Solution

  • To run your java program even when you exit out of your shell, Nohup is the simplest way.

    It'll detach a process you run from your current console and let it continue when you close the terminal. Run something like this.

    nohup java -jar my.jar &
    

    By default, it will pipe the output to nohup.out, so if you don't want that you could try:

    nohup java -jar my.jar > /dev/null &