6
$\begingroup$

If I try to start a Mathematica script in the background from the command line, like this:

math -script someFile.m &

then the process gets automatically suspended. Here's a terminal transcript for clarifications:

This happens both on Linux and OS X. Other programs don't typically stop when run in the background.

  • Why does this happen?

  • What can I do to prevent this?

$\endgroup$
1
  • 1
    $\begingroup$ should this be tagged as bug? $\endgroup$
    – a06e
    Oct 21, 2014 at 14:56

2 Answers 2

2
$\begingroup$

Mathematica for unknown reasons is waiting for input. Possible solution

echo | math -script someFile.m &
$\endgroup$
3
$\begingroup$

This is because your shell doesn't allow background processes to print to the console. For instance tcsh has this behavior by default:

% echo "a"&
[1] 26502
% 
[1]  + Suspended (tty output)        echo a
% fg
echo a
a

In pretty much all shells you should be able to disable this behavior with stty -tostop

% stty -tostop
% echo "a" &
[1] 26539
a
%
[1]    Done                          echo a

Re-enable the behavior with stty tostop

You could also redirect the output so it never hits stdout at all:

% echo "a" > /dev/null &
$\endgroup$
2
  • $\begingroup$ My test .m file simply contained a Print. I tested this on Mac with bash and on Linux with tcsh (and later bash). In both cases, the math process gets suspended and doesn't print anything until I resume it with fg. However, all other processes (including echo and python scripts) are able to print stuff to the terminal while in the background. $\endgroup$
    – Szabolcs
    Oct 19, 2013 at 0:56
  • $\begingroup$ @Szabolcs Strange, I'm stumped $\endgroup$
    – ssch
    Oct 19, 2013 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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