When I run `./command.sh &`, the background task is suspended. How can I keep it running?

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.


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.


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.