views:

204

answers:

2

Hi,

I am running matlab on 48 virtual machines and would like to automate it. I ssh into the machines then use matlab -r matlab_command > outfile.txt & to get the process to run in the background and run fine when I logout. The only problem is that when i jobs my process is stopped and won't start until I fg ^z bg. Is there a matlab flag so that I can run it in the background without having it stop?

Thanks, Mike

For clarification this is the order of commands that don't work

ssh server

matlab -r matlab_command > outfile.txt &

jobs

[1] Stopped

To fix this I

fg

^z

bg

logout

and it now works

+3  A: 

Use nohup command on UNIX to prevent MATLAB stop when you logout.

nohup matlab -nodisplay -nosplash -r matlab_command > outfile.txt &

And don't foret to include exit; at the end of matlab_command script.

UPDATE:

Try this solution: Is it possible to run MATLAB in the background under UNIX?

There is an explanation here.

yuk
In case you'd want a display, NoMachine (http://www.nomachine.com/) is very nice, since it allows you to log back into the server.
Jonas
Matlab doesn't stop when I logout, but it never actually starts until it has been run in the foreground at least once
msandbot
+3  A: 

The real clean solution to your problem is to use GNU Screen. Then you will not loose your Matlab session and you can always get back into the Matlab prompt. Very helpful if somebody went wrong with your Matlab code and you need to debug a little.

Just fire up 'screen' (after you have the package installed, included in all major distributions). You will have a typical prompt, but inside a persistent, virtual terminal. Start your matlab as usual, omit any backgrounding. Then press CTRL+A, D (first CTRL+A, then d). You will be out of screen. You can logout. If you want to get back to your screen session, run screen -r. If you want, you can also directly start screen matlab [...] in the first place. It will have the effect that your virtual session is also dropped when matlab quits.

ypnos
I always forget how useful `screen` can be! +1
Amro
I do not want to have to do any input such as this ctrl a d you speak of. I am trying to make a script to run matlab on 144 matlabs on 144 different VM's. I do not want to have to start each one by hand.
msandbot
Then screen is still suitable for you, as you can start it up just like the nohup case. What you also can do is use a screen that spawns 144 local sessions [a screen session can hold several virtual terminal sessions]. In each session then you automatically connect to one VM and run matlab. Then you don't log out and can easily monitor all the sessions by going through your one screen session. Not to say that you need to do that, it's just another option for your use-case. Being able to monitor sounds vital to me--with that number of sessions there will be some that fail.
ypnos