0

Suppose that I want to run a Java program so I would type

java myProgram

and then suppose that it prints some output to the screen but takes a few hours to finish running. If I want to keep working on the same terminal while it runs, what is the command that I should use? I tried & at the end and it did not seem to work.

0

3 Answers 3

2

Just add a & after the command. This will make the command run on the background.

Notice that you will still get the output of it, so you may want to redirect the output to /dev/null or to some configuration file.

E.g. in order to redirect both stdout and stderr:

java myProgram > /dev/null 2>&1 &
0

Since the program runs a long time, you may want to consider using screen. You can run the program and then start another command prompt with Control-a Control-c. You can do that as many times as you want, and be working on several things at once. Also, even if you log out and then back in later (just don't shut down), you can reconnect to screen and see how it's doing. Do "man screen" for info.

There is also tmux, which is a similar tool, but you'll need to install it.

0

I think screen will best answer your specific question, but it sounds like your workflow would benefit the most from using tabs.

To open a new tab in terminal, with the terminal selected you press Ctrl+T, and you can switch between tabs by pressing Ctrl+PgUp or Ctrl+PgDown to switch between them.

This quickly becomes intuitive, and ends up being efficient as you can quickly switch between tabs to check on long running programs, or quickly spawn more tabs as you busy the ones you're working in with long tasks.

Not the answer you're looking for? Browse other questions tagged .