6

This is what I'm running:

alexandma@ALEXANDMA-1-MBP ./command.sh &
[2] 30374
alexandma@ALEXANDMA-1-MBP
[2]  + suspended (tty output)  ./command.sh

I don't want it suspended to start, I want it to keep running in the background. I'm going to be running a bunch of these in a loop, so I need something that will work that way.

How can I keep it running?

7

It stops because of the reason given: it tries to output to tty. You can try to redirect the output if ./command.sh supports that, or run the command in a tmux or screen window of it's own. E.g.

 tmux new-window -n "window name" ./command.sh

and then view the list of windows created with tmux list-windows and attach to tmux with tmux attach.

That way the program will still wait for input/output to happen, but you can easily provide input once you go to the appropriate window and the output will just be captured without any activity.

  • Don't forget nohup – Sukima Nov 7 '14 at 4:51
  • When using tmux that is not necessary – Anthon Nov 7 '14 at 5:27
  • You answered my question with "It stops because of the reason given: it tries to output to tty. You can try to redirect the output if ./command.sh supports that" – Matt Alexander Nov 7 '14 at 12:17
  • @MattAlexander your comment seems incomplete – Anthon Nov 7 '14 at 12:18
11

Adding a detail to Anthon's explanation:

It is not always the case that a writing background process is stopped. This depends on the terminal setting tostop.

stty tostop
stty -tostop

can be used to toggle this setting. So if you want a background process to write to "another process's" terminal then you can keep it running but don't need tmux, screen or similar.

3

The easiest way to do this would be to execute the command as follows:

 nohup ./command.sh </dev/null &

I include the nohup in the event you are using a SH varient (not CSH varient) and would be terminating your session.

2

Install screen.

Once you've installed screen. Run it : # screen (you'll have a welcome screen when you first start it) Run your command : command.sh

The press Ctrl+a and then d.

It's gonna detach the screen launched on the server and keep your command running.

In order to go back to this screen, type :

screen -r

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.