转自:http://hi.baidu.com/imheaventian/item/04a27e14aa941c24f7625cef 后台运行matlab脚本文件的方法:nohup 例如:我在/home/jsh/yangting/文件夹下有个test2.m文件 那么,当matlab在/home/jsh/yangting/文件夹下打开时, 命令为 nohup matlab <test2.m> fill.out & 注意:在nohup运行成功后,不能直接点击关闭按钮,而应该按下任意键,恢复到输入状态,然后按exit命令退出。 使用命令: =================================== Usually, it is most effective and convenient to run Matlab locally, in particular for interactive work, but there are a number of reasons why you might want to run Matlab remotely across a network. For instance, your local machine may not have Matlab installed at all, or your local machine may not have sufficient memory for your task. In these cases, you can consider accessing another computer by remote login and running Matlab there. This concept only makes sense under Unix/Linux on the remote machine; Windows or Macintosh do not allow for remote access (as far as I know). Hence, for any new windows to be opened, also your local system needs to be Unix/Linux. However, the performance of such remote windows may be so slow that you will want to avoid them anyway and rather run Matlab purely inside your login shell; naturally, this precludes any graphical output and restricts this use to numerical tasks only. So, we want to start Matlab (i) without its desktop and (ii) without any graphics (including the splash screen); this can be accomplished by saying matlab -nodisplay . You could also use matlab -nodisplay -nojvm , which additionally does not start the JVM. In both cases, attempts to open plot and similar windows might be simply ignored or attempts to open the documentation windows might result in various error messages. The above is the most restrictive way in which to start Matlab. If in fact your local machine is Linux, you could use matlab -nodesktop -nosplash , which (i) does not start the desktop and (ii) suppresses the splash screen (the small window with Matlab's logo and version number that usually pops up briefly). But this way of starting Matlab does start the JVM and you have access to the HelpBrowser as well as to plot windows, if you later so desire (and are willing to wait for those to open, which might take a while depending on your network connection). Running Matlab in the Background (Under Linux)The idea of running a job in the background means that a software runs without any user interaction and additionally does not block your login shell. As remote access, this makes only sense under Unix/Linux. It applies both on your local machine, but might be particularly useful on a remote login; as in the previous section, this will be most useful for purely numerical (i.e., non-graphical) jobs. nohup \matlab -nojvm -nodisplay < driver.m >& driver.log &Here, the backslash in \matlab circumvents any possible alias you might have for Matlab (just to be on the safe side) and the options -nojvm -nodisplay suppress the starting of the JVM (and the startup of the desktop) and the opening of any windows. The final ampersand ("&") actually puts the command into the background, i.e., gives you the command-line prompt in your shell back. Aside from entering any usual commands now, you could in particular log out, without hanging or killing your job, because of the standard Unix/Linux command nohup before the call to Matlab. The file driver.m that must be present in the current directory is a Matlab script file (not: function file) that lists the commands to be executed by your job; if your job is actually performed by a function, this script file can simply be a single line that calls your function. For the remaining elements in the command-line above, I am assuming you are using the csh or tcsh shell; in other shells, the redirections may be slightly different. The "< " redirects stdin (namely from file driver.m) into Matlab. For the background run not to hang, there must not be any screen output, so the ">& " redirects both stdout and stderr to the file driver.log ; this file must not exist initially. Again, the redirection commands may be different in other shells and slight variations are possible (such as overwriting an existing log file). 无论是linux unix,用 nohup sh 'full command line' 都可以启动程序并让程序在后台运行,独立于终端。 |
|
来自: 复杂网络621 > 《matlab基础知识》